question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Postgres Native Types: Improve error when `uuid` is invalid

See original GitHub issue

Bug description

uuid accepts a string, but returns this cryptic error if your length is not 32 or 36 characters long.

How to reproduce

create table types (
  optionalUuid uuid,
  requiredUuid uuid not null,
  uuidList uuid[]
);
npx @prisma/cli@dev introspect
model types {
  optionaluuid            String?    @db.Uuid
  requireduuid            String     @db.Uuid
  uuidlist                String[]   @db.Uuid
}
npx @prisma/cli@dev generate
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()

async function main() {
  await prisma.$connect()
  await prisma.types.create({
    data: {
      optionaluuid: null || 'foo',
      requireduuid: 'bar',
      uuidlist: ['baz'],
    },
  })
}

main()
  .catch((err) => {
    console.error(err)
  })
  .finally(() => {
    prisma.$disconnect()
  })
./node_modules/.bin/ts-node index.ts
PrismaClientUnknownRequestError2: 
Invalid `prisma.types.create()` invocation in
/Users/m/Go/src/github.com/prisma/qa-native-types/index.ts:6:22

  2 const prisma = new PrismaClient()
  3 
  4 async function main() {
  5   await prisma.$connect()
→ 6   await prisma.types.create(
  Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: ToSql(18), cause: Some(Error(Parser(InvalidLength { expected: Any([36, 32]), found: 3 }))) }) })
    at PrismaClientFetcher.request (/Users/m/Go/src/github.com/prisma/qa-native-types/node_modules/@prisma/client/runtime/index.js:15875:15)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  clientVersion: '2.10.0-dev.58'
}

Expected behavior

I think a better error would be nice, I assumed that [36, 32] was an array of two bytes at first, rather than two optional lengths.

Environment & setup

Environment variables loaded from ./prisma/.env
@prisma/cli          : 2.10.0-dev.74
@prisma/client       : 2.10.0-dev.58
Current platform     : darwin
Query Engine         : query-engine 77abecc4840127ebdcc02b83ee1e2c9cc27009f2 (at ../../../../../.npm/_npx/6106/lib/node_modules/@prisma/cli/query-engine-darwin)
Migration Engine     : migration-engine-cli 77abecc4840127ebdcc02b83ee1e2c9cc27009f2 (at ../../../../../.npm/_npx/6106/lib/node_modules/@prisma/cli/migration-engine-darwin)
Introspection Engine : introspection-core 77abecc4840127ebdcc02b83ee1e2c9cc27009f2 (at ../../../../../.npm/_npx/6106/lib/node_modules/@prisma/cli/introspection-engine-darwin)
Format Binary        : prisma-fmt 77abecc4840127ebdcc02b83ee1e2c9cc27009f2 (at ../../../../../.npm/_npx/6106/lib/node_modules/@prisma/cli/prisma-fmt-darwin)
Studio               : 0.304.0
Preview Features     : nativeTypes

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
matthewmuellercommented, Oct 26, 2021

No update yet, thanks for the reminder though!

2reactions
deveploncommented, Oct 24, 2021

Any update on this? I’ve received this error many times already and I could start to validate it but it is quite annoying to do it throughout the system. Thanks in advance!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to specify on error behavior for postgresql conversion to ...
I need to write a query to join 2 tables based on UUID field. Table 1 contains user_uuid of type uuid. Table 2...
Read more >
Documentation: 15: 8.12. UUID Type - PostgreSQL
UUID Type. The data type uuid stores Universally Unique Identifiers (UUID) as defined by RFC 4122, ISO/IEC 9834-8:2005, and related standards. (Some systems ......
Read more >
Postgres support for UUID [closed] - DBA Stack Exchange
My understanding is that Postgres supports UUID data type out-of-the-box. I'm running Postgres on Amazon RDS with Engine version 10.6 and am ...
Read more >
Getting more with PostgreSQL purpose-built data types
The following steps delete the row with the invalid UUID and change the data type of the source_id column to UUID:.
Read more >
The Basics Of PostgreSQL UUID Data Type
In this tutorial, you will learn how to use PostgreSQL UUID data type and how ... UUID in the distributed systems because it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found