-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prisma VS Code extension with mongodb provider crashes when a relation field/type is not defined #1466
Comments
Thanks @KarthikRaju391, I can confirm the crash on my end too. |
Do you get the same error when running |
Minimal schema for reproduction datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model User {
// id String @id @default(auto()) @map("_id") @db.ObjectId
field NotDefined
// field NotDefined?
// field NotDefined[]
s
} It seems that it only happens with the |
@KarthikRaju391 Make sure to define We can keep this issue to improve the experience here and avoid the unexpected crash. |
@Jolg42, it's not because of |
It's not really affecting the functionality of the extension, that is, autocompleting relations, showing common errors, etc. But, when editing the file, the error I mentioned keeps coming up. |
I can confirm this error is happening with me. |
I think this is the minimal reproduction: datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model Foo {
bar Bar[]
} Put this in a schema file, and hover over
From looking at https://github.com/prisma/prisma-engines/blob/4a1c72356ffb884a5752157c21d8bac67afd1720/psl/parser-database/src/walkers/model.rs#L104, somehow this seems to try to iterate over primary keys - which do not exist for this model. (A stracktrace would be useful in addition to where it crashes...) |
I a PR to get the stack trace printed in logs #1474
|
What I found out is that it fails here https://github.com/prisma/prisma-engines/blob/4a1c72356ffb884a5752157c21d8bac67afd1720/psl/parser-database/src/walkers/model.rs#L74-L76 |
The code action for adding the missing `@map` attribute for MongoDB relies on the parser database being populated to be able to search for the primary key of the model. However, the parser database constructor returns early when there are validation errors during name and types resolution, so trying to access model attributes later on leads to runtime errors as those structures are not constructed. This commit implements populating the model and enum attributes with stub default values before returning. As no further validation will happen, and the engines do not work with invalid schemas, this should not lead to incorrect behaviour. However, the code in the language tools should take into account that accessing the model or enum attributes in invalid schemas, although won't lead to crashes anymore, will return incomplete information. Fixes: prisma/language-tools#1466
…4087) The code action for adding the missing `@map` attribute for MongoDB relies on the parser database being populated to be able to search for the primary key of the model. However, the parser database constructor returns early when there are validation errors during name and types resolution, so trying to access model attributes later on leads to runtime errors as those structures are not constructed. This commit implements populating the model and enum attributes with stub default values before returning. As no further validation will happen, and the engines do not work with invalid schemas, this should not lead to incorrect behaviour. However, the code in the language tools should take into account that accessing the model or enum attributes in invalid schemas, although won't lead to crashes anymore, will return incomplete information. Fixes: prisma/language-tools#1466
Bug description
I have set up Prisma with MongoDB provider but every time I try to edit the file, the following error is thrown.
And this is what the terminal output of the Prisma language server shows:
Prisma
How to reproduce
Expected behavior
No response
Prisma information
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: