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

chore(cause): added error cause #32

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Conversation

dreamsparkx
Copy link

@dreamsparkx dreamsparkx commented Mar 5, 2025

@@ -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`, {

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added more cases

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

Successfully merging this pull request may close these issues.

5 participants