-
Notifications
You must be signed in to change notification settings - Fork 15
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
chore(cause): added error cause #32
base: master
Are you sure you want to change the base?
Conversation
@@ -188,7 +189,9 @@ exports.create = function create(parent) { | |||
try { | |||
data = handler(input); | |||
} catch (err) { | |||
error = err; | |||
error = new Error(`Error occurred while resolving "${proto}" protocol with value "${input}" at "${handler.name || 'unknown'}" handler`, { |
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.
After closely looking at this, I think right now, we are only dealing with synchronous handlers function handler(input)
, but we actually need to do something similar for asynchronous handlers, which have a different signature function handler(input, cb)
.
I think we'll need to do wrap L201 with a callback that simply wraps handler
and decorates errors with the additional information before propagating. Something like:
- return handler
+return function handl(...args) {
+ const next = args[args.length - 1];
+
+ function cb(err, ...ar) {
+ return next(new Error('error with more info', { cause: err }), ...ar);
+ }
+
+ args[args.length - 1] = cb;
+
+ return handler(...args);
+}
The changes should look roughly like that, but I'd test and update/add new tests if necessary to ensure those changes behave as intended.
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.
added more cases
related: krakenjs/confit#93