Catch errors thrown by onInclude#622
Conversation
When using the `.then($1, $2)` function, any errors thrown from `$1` will *not* be delegated to `$2`. Changing to `.then($1).catch($2)` makes sure that even errors from `$1` gets delegated to `$2`. Found by this proposed standard rule: standard/eslint-config-standard#129
|
Seems like one of the builds hanged, would you mind restarting it? |
|
Build retriggered. The reason this is built this way is that we're calling The native However, your PR did bring to my attention that our implementation is slightly incorrect, since function handleFilter (onInclude, destStat, src, dest, opts, cb) {
Promise.resolve(opts.filter(src, dest))
.then(include => {
if (include) {
if (destStat) return onInclude(destStat, src, dest, opts, cb)
return onInclude(src, dest, opts, cb)
}
})
.then(() => cb(), error => cb(error))
} |
|
Hmm, I think the code that you proposed might call the callback There is another problem as well, if Unfortunately, it's quite hard to mix promises and callbacks, especially when trying to call a callback from a function that uses promises. My personal recommendation, and I would be happy to help with this if you want to, is to just use Promises internally, and then convert to callbacks only at the outmost API-layer. This "callbackification" can then be handled in a proper way easily, using something like this: https://nodejs.org/api/util.html#util_util_callbackify_original |
|
Didn't find any proper callbackification package for Node 6.x, so I ported the built-in one from Node 10 to also work on Node.js 6: https://github.com/LinusU/util-callbackify If we use that one it will handle all the rejections properly, including when errors are thrown from the callback. |
You're right, I wasn't looking closely at the code here.
It will be an
This might be a good approach. For converting back to callbacks, we'd use https://github.com/RyanZim/universalify since all fs-extra supports both promises and callbacks, and it's already a dependency. @manidlou what are your thoughts on migrating Regardless what we decide, I don't think this is a giant rush since we've never seen a problem as a result of this in the real world. |
|
@RyanZim I'm fine with migrating callbacks to promises internally. I'd just say if we do it for |
|
Given that we've never seen any problems here in the real world, I'm gonna close this out. |
When using the
.then($1, $2)function, any errors thrown from$1will not be delegated to$2. Changing to.then($1).catch($2)makes sure that even errors from$1gets delegated to$2.Found by this proposed standard rule: standard/eslint-config-standard#129