prisma validate error - thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value'
See original GitHub issueBug description
I have a self-referencing table model in my schema that looks like this:
model Folder {
id String @db.Char(30) @default(cuid()) @id
name String @db.MediumText
childFolders Folder[] @relation("ChildToParentFolder")
parentFolderId String? @db.Char(30)
parentFolder Folder? @relation("ChildToParentFolder", fields: [parentFolderId], references: [id])
}
But when I run DEBUG="*" npx prisma validate
I see
prisma:loadEnv project root found at [...path omited...]\package.json +0ms
prisma:tryLoadEnv Environment variables loaded from [...path omited...]\.env +0ms
[dotenv][DEBUG] did not match key and value when parsing line 1: # Environment variables declared in this file are automatically made available to Prisma.
[dotenv][DEBUG] did not match key and value when parsing line 2: # See the documentation for more detail: https://pris.ly/d/prisma-schema#using-environment-variables[dotenv][DEBUG] did not match key and value when parsing line 3:
[dotenv][DEBUG] did not match key and value when parsing line 4: # Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server and
MongoDB (Preview).
[dotenv][DEBUG] did not match key and value when parsing line 5: # See the documentation for all the connection string options: https://pris.ly/d/connection-strings
[dotenv][DEBUG] did not match key and value when parsing line 6:
[dotenv][DEBUG] did not match key and value when parsing line 12:
Environment variables loaded from .env
prisma:engines binaries to download libquery-engine, migration-engine, introspection-engine, prisma-fmt +0ms
Prisma schema loaded from prisma\schema.prisma
prisma:getDMMF Using CLI Query Engine (Node-API) at: [...path omited...]\node_modules\@prisma\engines\query_engine-windows.dll.node +0ms
thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', libs\datamodel\connectors\dml\src\model.rs:290:47
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: SyntaxError: Unexpected token c in JSON at position 0
at JSON.parse (<anonymous>)
at getDmmfNodeAPI ([...path omited...]\node_modules\prisma\build\index.js:36492:28)
at async getDMMF ([...path omited...]\node_modules\prisma\build\index.js:36471:17)
at async Object.parse ([...path omited...]\node_modules\prisma\build\index.js:104072:5)
at async main ([...path omited...]\node_modules\prisma\build\index.js:105393:18)
I tried RUST_BACKTRACE=1
to get more info but that spit out the same thing except with the suggestion to try RUST_BACKTRACE=full
, so I tried that and get this:
$ RUST_BACKTRACE=full npx prisma validate
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', libs\datamodel\connectors\dml\src\model.rs:290:47
stack backtrace:
0: 0x7ffb3d4f042e - napi_register_module_v1
1: 0x7ffb3d50f5ba - rust_eh_personality
2: 0x7ffb3d4e8d78 - napi_register_module_v1
3: 0x7ffb3d4f3146 - napi_register_module_v1
4: 0x7ffb3d4f2c34 - napi_register_module_v1
5: 0x7ffb3d4f37a5 - napi_register_module_v1
6: 0x7ffb3d4f335f - napi_register_module_v1
7: 0x7ffb3d4f0d77 - napi_register_module_v1
8: 0x7ffb3d4f32e9 - napi_register_module_v1
9: 0x7ffb3d6a00d0 - rust_eh_personality
10: 0x7ffb3d6a001c - rust_eh_personality
11: 0x7ffb3d019a5f - napi_register_module_v1
12: 0x7ffb3ce5a436 - napi_register_module_v1
13: 0x7ffb3cebef74 - napi_register_module_v1
14: 0x7ffb3ce5826f - napi_register_module_v1
15: 0x7ffb3c22644d - <unknown>
16: 0x7ffb3c23d010 - <unknown>
17: 0x7ffb3c25514b - <unknown>
18: 0x7ff74de2aac7 - node::Stop
19: 0x7ff74e67f11f - v8::internal::Builtins::builtin_handle
20: 0x7ff74e67e6b4 - v8::internal::Builtins::builtin_handle
21: 0x7ff74e67e9a8 - v8::internal::Builtins::builtin_handle
22: 0x7ff74e67e7f3 - v8::internal::Builtins::builtin_handle
23: 0x7ff74e75d67d - v8::internal::SetupIsolateDelegate::SetupHeap
24: 0x7ff74e6f3762 - v8::internal::SetupIsolateDelegate::SetupHeap
25: 0x7ff74e721810 - v8::internal::SetupIsolateDelegate::SetupHeap
26: 0x7ff74e79fc6e - v8::internal::SetupIsolateDelegate::SetupHeap
27: 0x7ff74e713a10 - v8::internal::SetupIsolateDelegate::SetupHeap
28: 0x7ff74e6f130c - v8::internal::SetupIsolateDelegate::SetupHeap
29: 0x7ff74e5c0b10 - v8::internal::Execution::CallWasm
30: 0x7ff74e5c0c1b - v8::internal::Execution::CallWasm
31: 0x7ff74e5c165a - v8::internal::Execution::TryCall
32: 0x7ff74e5a1735 - v8::internal::MicrotaskQueue::RunMicrotasks
33: 0x7ff74e5a1490 - v8::internal::MicrotaskQueue::PerformCheckpoint
34: 0x7ff74de80904 - node::CallbackScope::~CallbackScope
35: 0x7ff74de80d3b - node::CallbackScope::~CallbackScope
36: 0x7ff74de789c4 - v8::internal::compiler::Operator::EffectOutputCount
37: 0x7ff74dde5eb5 - SSL_get_quiet_shutdown
38: 0x7ff74ddd933e - v8::base::CPU::has_sse
39: 0x7ff74deb4e47 - uv_timer_stop
40: 0x7ff74deb141b - uv_async_send
41: 0x7ff74deb0bac - uv_loop_init
42: 0x7ff74deb0d4a - uv_run
43: 0x7ff74dda8a45 - v8::internal::AsmJsScanner::GetIdentifierString
44: 0x7ff74de21227 - node::Start
45: 0x7ff74dc7685c - RC4_options
46: 0x7ff74ec31c08 - v8::internal::compiler::RepresentationChanger::Uint32OverflowOperatorFor
47: 0x7ffb97cc7034 - BaseThreadInitThunk
48: 0x7ffb97e02651 - RtlUserThreadStart
Error: Unexpected token c in JSON at position 0
How to reproduce
- Make self-referencing model in Prisma2 schema as shown above
- Run
npx prisma validate
- become saddened by error
Expected behavior
Ideally, validation would check the file
Environment & setup
- OS: Windows (above from within Git Bash terminal in VS Code)
- Database: MySQL
- Node.js version: v14.18.0
Prisma Version
prisma : 3.4.0
@prisma/client : 3.4.0
Current platform : windows
Query Engine (Node-API) : libquery-engine 1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85 (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine : migration-engine-cli 1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85 (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core 1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85 (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary : prisma-fmt 1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85 (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : 1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85
Studio : 0.438.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Panicked at 'called `Option::unwrap()` on a `None` value ...
Hi! I'm currently porting the Lox language from Crafting Interpreters , but I've been stuck for a while in an annoying bug.
Read more >Indexes - Prisma
Prisma allows configuration of database indexes, unique constraints and primary key constraints. This is in General Availability in versions 4.0.0 and later ...
Read more >Thread 'main' panicked at 'called `Result::unwrap()` on an `Err ...
thread 'main' panicked at 'called Result::unwrap() on an Err value: Error("expected value", line: 1, column: 1)', src/models.rs:43:38
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
In Prisma 3.3.0 the
validate
andformat
comamnd gave a much more helpful error message:I can confirm that this schema causes a crash:
So although something might be weird or wrong with your schema, the crash is of course unexpected and should be a helpful validation error message instead.
Using
prisma format
on the schema leads to validation errors:Using
Format Document
in the VSCode extension has a different effect:Running that again, keeps changing the schema!
(adds
@unique
to the last field without a space)(fixes the order in the last field and adds the space)