-
Notifications
You must be signed in to change notification settings - Fork 181
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
Handle rejections in migration actions #148
Conversation
Before they were resulting in unhandled rejection errors!
if (action.length === 2) { | ||
action(pgm, resolve); | ||
} else { | ||
const result = action(pgm); | ||
// result conforms to Promises/A+ spec | ||
if (typeof result === 'object' && typeof result.then === 'function') { | ||
result.then(resolve); | ||
result.then(resolve).catch(err => reject(err)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing!
I would prefer .catch(reject)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not the same thing!
In fact if you .catch(reject)
the error isn't passed to the reject call and thus you won't get the error message for the rejection.
Instead if you do .catch(err => reject(err))
you pass the error and when the rejection is handled it will print out the error message to the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is almost the same thing as .catch(reject)
is equivalent to .catch((...args) => reject(...args))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try the difference in your code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried and got same result
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Promise.reject(new Error('fail')).catch(console.log.bind(console));
Promise.reject(new Error('fail')).catch(err => console.log(err));
have same result...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
Is it possible to merge changes? |
Can you release a new version with the changes? Thanks a lot |
It is already released as 2.15.0 |
Ok thanks
Il 11 gen 2018 5:51 PM, "Jan Doležel" <[email protected]> ha scritto:
… It is already released as 2.15.0
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#148 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAUkPcXu69hJysmFAhxCNcvqdp94QTceks5tJjwLgaJpZM4RWjCz>
.
|
If an asynchronous up/down migration function is rejected, node-pg-migrate at the moment fails, causing a unhandled rejection error!
This patch adds support for action rejections.