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

too short stack traces after nextTick call on document validation #1034

Closed
kof opened this issue Aug 2, 2012 · 4 comments
Closed

too short stack traces after nextTick call on document validation #1034

kof opened this issue Aug 2, 2012 · 4 comments

Comments

@kof
Copy link

kof commented Aug 2, 2012

I have a validation error:

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.

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

@hannesgassert
Copy link

+1

@hildoer
Copy link
Contributor

hildoer commented Dec 4, 2013

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.

@refack
Copy link
Contributor

refack commented Dec 4, 2013

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.

@vkarpov15
Copy link
Collaborator

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.

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

No branches or pull requests

5 participants