You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeError: Cannot read property 'length' of undefined
Stacktrace (most recent call last):
File "/app/app/server/app/models/user.js", line 61, in model.
return str.length < 20;
File "/app/node_modules/mongoose/lib/schematype.js", line 345
validate(validator.call(scope, value), message);
File "native", line 0, in Array.forEach
File "/app/node_modules/mongoose/lib/schematype.js", line 333, in SchemaString.doValidate
this.validators.forEach(function (v) {
File "/app/node_modules/mongoose/lib/document.js", line 777, in Array.18
p.doValidate(self.getValue(path), function (err) {
File "node.js", line 190, in EventEmitter._tickCallback
Stacktrace there is a way too short, it starts from p.doValidate method call, so I am not able to understand which code is causing this validation issue.
nextTick, prior to node 0.10 was a way of breaking up CPU bound work to allow IO to interleave. On node 0.10 and later, nextTick doesn't allow IO to interleave before the nextTick callback is fired, but still may be required for some less robust logic. I don't think the less robust logic issue is a problem here. But, I am digressing a bit.
Getting to your problem specifically... For development, you can just modify the source code that is causing the problem and replace instances of process.nextTick(func); with func();. You will still have the issue of the stack trace only reach back as far back as the IO the triggered the execution block, but you will see more than what you are getting now. Just remember to restore everything when you are done debugging, possibly with an rm -rf node_modules/mongoose; npm install command.
I use longjohn which monkey patches some core funcs so that stack traces persist execution context.
P.S. In node 0.12 we'll have addAsychListner (nodejs/node-v0.x-archive#6011) and verius CLS to solve that even better.
IMO this is outside the scope of mongoose. You can get long stack traces by using longjohn or by using bluebird promises and setting bluebird's long stack traces option, we don't need to reinvent the wheel.
I have a validation error:
Stacktrace there is a way too short, it starts from p.doValidate method call, so I am not able to understand which code is causing this validation issue.
The reason for this is nextTick call before it https://github.com/LearnBoost/mongoose/blob/master/lib/document.js#L847
Is there a real reason to use nextTick there and how do deal with this?
Best,
Oleg
The text was updated successfully, but these errors were encountered: