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

Unhandled Rejection #53

Open
yamila-fraiman opened this issue Feb 19, 2018 · 5 comments
Open

Unhandled Rejection #53

yamila-fraiman opened this issue Feb 19, 2018 · 5 comments

Comments

@yamila-fraiman
Copy link

Suddenly my server stop working and throws the following error. For the moment, I resolved it by dropping the ojlinttaskcollections db.

You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
TypeError: Cannot read property '_id' of undefined
    at rollbackSave (/home/inamu/webserver/node_modules/fawn/lib/roller.js:137:30)
    at /home/inamu/webserver/node_modules/fawn/lib/roller.js:98:39
    at tryCatcher (/home/inamu/webserver/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/inamu/webserver/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/home/inamu/webserver/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromiseCtx (/home/inamu/webserver/node_modules/bluebird/js/release/promise.js:606:10)
    at Async._drainQueue (/home/inamu/webserver/node_modules/bluebird/js/release/async.js:138:12)
    at Async._drainQueues (/home/inamu/webserver/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/home/inamu/webserver/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:574:20)
    at tryOnImmediate (timers.js:554:5)
    at processImmediate [as _immediateCallback] (timers.js:533:5)
@e-oj
Copy link
Owner

e-oj commented Feb 19, 2018

What version of Fawn? and can you share the code that causes that error?

@yamila-fraiman
Copy link
Author

yamila-fraiman commented Feb 19, 2018

2.1.5
I found the error was because I forgot to call next on pre save in the second transaction. But I think that lib should catch exceptions to prevent breaking the server if there is an error.

`
let transaction = Fawn.Task();

		transaction.save('User', {
			email: req.body.user.email
		});

		let data = lodash.pick(req.body, fields);
		data.user = {$ojFuture: '0._id'};
		transaction.save('Organization', data);`

@e-oj
Copy link
Owner

e-oj commented Feb 19, 2018

The error bubbles up to the user when something goes wrong that the user needs to know about. You can always catch any errors that occur to prevent crashing.

let task = Fawn.Task();

task.save(...);
task.update(...);

try{
  let result = await task.run();
}
catch(err){
  console.log(err.message);
}

@yamila-fraiman
Copy link
Author

I use the following code but wasn't enough

transaction.run({useMongoose: true}) .then((results) => {}) .catch((err) => {})

@e-oj
Copy link
Owner

e-oj commented Feb 19, 2018

That's strange. I'll look into it.

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

2 participants