Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

UUID caster called out of scope, and missing schema path ino. #15202

Closed
2 tasks done
jsas opened this issue Jan 25, 2025 · 0 comments · Fixed by #15215
Closed
2 tasks done

UUID caster called out of scope, and missing schema path ino. #15202

jsas opened this issue Jan 25, 2025 · 0 comments · Fixed by #15215
Labels
has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
Milestone

Comments

@jsas
Copy link

jsas commented Jan 25, 2025

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

8.9.5

Node.js version

20.5

MongoDB server version

6

Typescript version (if applicable)

No response

Description

./lib/schema/uuid.js line~112

SchemaUUID._cast = function(value) {
   ...
    throw new CastError(SchemaUUID.schemaName, value, this.path);
}

if this throws, there is no (this) path, so the validation error reason ends up looking like:

"reason: TypeError: Cannot read properties of undefined (reading 'path')"

Steps to Reproduce

import mongoose, { Schema } from 'mongoose'

const Example = mongoose.model('example', new Schema({
uuid: 'UUID'
}))

const doc = new Example({
uuid: '11111111-1111-1111-1111-111111111111'
})

doc.save()

// error reason reads reason: TypeError: Cannot read properties of undefined (reading 'path')

Expected Behavior

reason: CastError: Cast to UUID failed for value "11111111-1111-1111-1111-111111111111" (type string) at path "uuid"

@vkarpov15 vkarpov15 added this to the 8.9.6 milestone Jan 25, 2025
@vkarpov15 vkarpov15 added the has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue label Jan 25, 2025
vkarpov15 added a commit that referenced this issue Jan 31, 2025
fix(schema): improve reason for UUID cast error, currently a TypeError
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants