prisma: CLI crash when run on empty `schema.prisma`

  • npm init -y
  • npm install prisma@dev
  • Then:
C:\Users\Jan\Documents\throwaway\envRepro  (envRepro@1.0.0)
λ npx prisma db push
Prisma schema loaded from schema.prisma
Error: Get config thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', query-engine\query-engine\src\opt.rs:148:21
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

C:\Users\Jan\Documents\throwaway\envRepro  (envRepro@1.0.0)
λ npx prisma migrate dev
Prisma schema loaded from schema.prisma
Error: Get config thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', query-engine\query-engine\src\opt.rs:148:21
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

vs. handled error in Introspection:

C:\Users\Jan\Documents\throwaway\envRepro  (envRepro@1.0.0)
λ npx prisma introspect
Prisma schema loaded from schema.prisma

Introspecting based on datasource defined in schema.prisma …
Error: There is no datasource in the schema.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 16 (16 by maintainers)

Commits related to this issue

Most upvoted comments

We should:

  1. change “datamodel path” to “schema path” or something that users could understand,
  2. add a snapshot test for all these commands in its current state,
  3. then decide if there is a better way to handle that (in the CLI for example where we can shot a unified and nicer error message instead of letting getdmmf and others handle this problem.

Side question: Why are db push and db pull different than the others?

Error message is now different in 3.6.0:

C:\Users\Jan\Documents\throwaway\7186  (7186@1.0.0)
λ npx prisma db push
Prisma schema loaded from schema.prisma
Error: Cannot read property 'url' of undefined

C:\Users\Jan\Documents\throwaway\7186  (7186@1.0.0)
λ npx prisma migrate dev
Prisma schema loaded from schema.prisma
Error: Cannot read property 'url' of undefined

This now looks like a TypeScript problem in the Migrate CLI, probably trying to access the datasource.url which does not exist as the file is empty.

Update:

db pull now also shows the same behavior instead of a good error message before:

C:\Users\Jan\Documents\throwaway\7186  (7186@1.0.0)
λ npx prisma db pull
Prisma schema loaded from schema.prisma
Error: Cannot read property 'url' of undefined

Pushing this to team/client because the crash is in the query engine (most likely getConfig).