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
ValidatorError not catched by try/catch #14101
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Comments
The Validator error is not catched when there is an array of arrays .
if there is an error in one of the element a Validator error is thrown and is not catched by the try/catch block around it |
vkarpov15
added
the
needs repro script
Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue
label
Nov 25, 2023
IslandRhythms
added
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
and removed
needs repro script
Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue
labels
Nov 27, 2023
const mongoose = require('mongoose');
const optionsSchema = new mongoose.Schema({
val: {
type: Number,
required: true
}
});
const testSchema = new mongoose.Schema({
name: String,
options: {
type: [[optionsSchema]],
required: true
}
});
const Test = mongoose.model('Test', testSchema);
async function run() {
await mongoose.connect('mongodb://localhost:27017');
await mongoose.connection.dropDatabase();
await Test.create({ name: 'Test' });
console.log(await Test.findOne())
console.log('done');
}
run(); |
Correct repro script: const mongoose = require('mongoose');
const optionsSchema = new mongoose.Schema({
val: {
type: Number,
required: true
}
});
const testSchema = new mongoose.Schema({
name: String,
options: {
type: [[optionsSchema]],
required: true
}
});
const Test = mongoose.model('Test', testSchema);
async function run() {
await mongoose.connect('mongodb://localhost:27017');
await mongoose.connection.dropDatabase();
await Test.create({ name: 'Test', options: [[{ val: null }]] });
console.log(await Test.findOne())
console.log('done');
}
run().catch(err => console.log('caught', err)); |
vkarpov15
added a commit
that referenced
this issue
Nov 29, 2023
… array so nested document arrays use correct constructor Fix #14101
vkarpov15
added a commit
that referenced
this issue
Dec 1, 2023
fix(schema): avoid creating unnecessary clone of schematype in nested array so nested document arrays use correct constructor
vkarpov15
added a commit
that referenced
this issue
Dec 1, 2023
… array so nested document arrays use correct constructor Fix #14101
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisites
Mongoose version
^7.5.0
Node.js version
18.18.0
MongoDB server version
MongoDB Atlas
Typescript version (if applicable)
^5.2.2
Description
The ValidatorError thrown by mongoose is not catched by try/catch block
Error:
Steps to Reproduce
Expected Behavior
The error should be catched by the closest try/catch block
The text was updated successfully, but these errors were encountered: