Skip to content
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

Mystery error thrown with no reference to query or operation #10845

Closed
adamreisnz opened this issue Oct 5, 2021 · 9 comments
Closed

Mystery error thrown with no reference to query or operation #10845

adamreisnz opened this issue Oct 5, 2021 · 9 comments
Milestone

Comments

@adamreisnz
Copy link
Contributor

Do you want to request a feature or report a bug?
Bug, but possibly caused by user error/invalid input

What is the current behavior?
This error is thrown, but the stack trace doesn't tell me where in the app it's thrown from, so I have no clues to go on:

TypeError: Cannot read properties of undefined (reading 'toArray')
  File "node_modules/mongoose/lib/query.js", line 2148, col 21, in null.<anonymous>
  File "node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js", line 223, col 9, in NativeCollection.<computed> [as find]
  File "node_modules/mongoose/lib/query.js", line 2143, col 31, in model.Query.<anonymous>
  File "node_modules/mongoose/lib/helpers/query/wrapThunk.js", line 27, col 8, in model.Query._wrappedThunk [as _find]
  File "node_modules/kareem/index.js", line 370, col 33, in null.<anonymous>
  File "node:internal/process/task_queues", line 78, col 11, in processTicksAndRejections
  File "node_modules/mongoose/lib/helpers/promiseOrCallback.js", line 31, col 10, in promiseOrCallback
  File "node_modules/mongoose/lib/query.js", line 4556, col 10, in model.Query.exec
  File "node_modules/mongoose/lib/query.js", line 4639, col 15, in model.Query.Query.then

If the current behavior is a bug, please provide the steps to reproduce.
Unknown

What is the expected behavior?
Maybe this error should be handled internally in Mongoose to clarify what exactly is going wrong, as to provide a hint to the developers to indicate what query/operation is causing it to fail.

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.

  • MongoDB shell version v5.0.2
  • Node 16.3.0
  • Mongoose 6.0.7
@IslandRhythms IslandRhythms added the needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity label Oct 6, 2021
@IslandRhythms
Copy link
Collaborator

Can you provide the code you are running that is throwing this error?

@adamreisnz
Copy link
Contributor Author

adamreisnz commented Oct 6, 2021 via email

@adamreisnz
Copy link
Contributor Author

adamreisnz commented Oct 6, 2021 via email

@vkarpov15 vkarpov15 added this to the 6.0.10 milestone Oct 6, 2021
@vkarpov15 vkarpov15 added docs This issue is due to a mistake or omission in the mongoosejs.com documentation and removed needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity docs This issue is due to a mistake or omission in the mongoosejs.com documentation labels Oct 6, 2021
@vkarpov15
Copy link
Collaborator

Random side note: I've never seen this particular error "Cannot read properties of undefined". Normally it would be "Cannot read property 'toArray' of undefined". Do you know why this error message is different on your end?

@adamreisnz
Copy link
Contributor Author

adamreisnz commented Oct 6, 2021

@vkarpov15 thanks for fixing, is there something we can do on our end to figure out where this was thrown from (other than using .exec() everywhere)?

I know, we started seeing these errors formatted in this different manner recently as well. I suspect they may have changed the wording for these errors in a recent javascript engine update, as they started creeping up in Node 16 as well as newer browser versions.

For example, the following error changed from:

Cannot read property 'document' of null

to:

Cannot read properties of null (reading 'document')

🤷🏼

@vkarpov15
Copy link
Collaborator

@adamreisnz I don't think so, the find() call is swallowing the error message. My best guess would be something along the lines of calling find() before mongoose.connect(), because there are very few cases where find() should throw an error.

@adamreisnz
Copy link
Contributor Author

Ok, would a possible scenario be if .find() is called when mongo has lost connection?
I will update to the latest Mongoose version later on and see if we can surface the actual error. Thanks.

@IslandRhythms
Copy link
Collaborator

IslandRhythms commented Oct 6, 2021

would a possible scenario be if .find() is called when mongo has lost connection?

@adamreisnz try adding event handlers and see the execution order https://mongoosejs.com/docs/connections.html#connection-events

@vkarpov15
Copy link
Collaborator

@adamreisnz I think it is possible this error was caused by Mongoose being disconnected for more than serverSelectionTimeoutMS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants