-
Notifications
You must be signed in to change notification settings - Fork 33
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
Serialize errors with cause #105
Serialize errors with cause #105
Conversation
The error serializer already handles the case where an error is not of type Error (or AggregateError) well, so there is no reason to add special handling for that. We can simply pass whatever is in `cause` into the serializer, and we should get a serialized result out.
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.
lgtm
@voxpelli could you take a look? |
CI is failing |
It seems that my assumption (comment) "message serialization already walks cause-chain" is only true in Node.js 16 for some reason? (I am running 16 locally, too, so it might be...) https://github.com/pinojs/pino-std-serializers/pull/105/files#diff-a6ff895a4ce70729791324c8118f43cffada5a9e9cfe42ea1df4a18707f2c430R207 This is odd to me, because it looks like the same functionality should be happening (cf. what was done in #76). Could it be that earlier Node.js versions don't support the |
Oh yes, looking at it now what fails is the following lines:
I'll try to look at other tests to see if similar things are handled there. |
In the other tests (of cause serialization into the error message) the This could be an approach, of course, but it kind of obscures what the case we are trying to support is... Open to input on how to approach this 😄 |
That's totally ok, follow the other tests. |
Fixed 😄 |
Hmm this comment on recursion by @jsumners made me realize that in #78 there was added some more checks, so it only recurses if Should I support that here too? |
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.
Looks good to me.
Um, so this now means that apart from the So we're basically having two systems for serializing the causes at once? I would say that either we walk the cause chain as this PR did, or we summarize the cause chain through the Never do the both at once and especially never do the both recursively? Sorry for not responding earlier :/ |
@voxpelli I agree, and raised the issue here, too: #94 (comment) |
And in https://github.com/pinojs/pino-std-serializers/pull/78/files#diff-71c187d84f435004e68161a25e470d823f4de310a1d39b531cc02a90f3730149R56 we specifically opted out causes from recursion: if (val instanceof Error && key !== 'cause') {
/* eslint-disable no-prototype-builtins */
if (!val.hasOwnProperty(seen)) { I think it should be rewritten as: if (val instanceof Error) {
/* eslint-disable no-prototype-builtins */
if (key !== 'cause' && !val.hasOwnProperty(seen)) { That way it will exclude all |
This reverts commit ae83956.
Instead rely on its content being appended to the message and the stack. This is an alternative fix to pinojs#94, replacing pinojs#105 and pinojs#108 + makes pinojs#109 not needed
I'm not sure I understand the explicit opting out of recursing over |
Let's discuss it in #110 |
…ead (#110) * Revert "Nested VError causes (#108)" This reverts commit 5b88f7e. * Revert "Serialize errors with cause (#105)" This reverts commit ae83956. * Never serialize `.cause` when an `Error` Instead rely on its content being appended to the message and the stack. This is an alternative fix to #94, replacing #105 and #108 + makes #109 not needed * Add tests * Add explainer comment
Related to #76 and #78 which add serialization of
cause
into error messages.This PR fixes #94 by making sure the chain of causes found in
err.cause
is serialized in full, bringing the final serialized result closer to what is printed by other serializers (e.g. those in the Node.js CLI and browser consoles).