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

default Internal Error formatting of uncaught errors drops cause #159

Open
seansfkelley opened this issue Mar 26, 2024 · 1 comment
Open

Comments

@seansfkelley
Copy link

seansfkelley commented Mar 26, 2024

In ES2022 (I think?), Errors gained a cause attribute. The default behavior of Clipanion to format the error doesn't check for this field, only stack, so the causes of rethrown errors are silently dropped.

I'd be happy to open a PR to add cause support to the default formatting behavior. I would have already but to make it typesafe I would have to change the tsconfig.json's lib it compiles against (and potentially the TypeScript version itself?), and I don't know what compatibility requirements you have. cause is supported since Node 16, which is now EOL.

@seansfkelley
Copy link
Author

seansfkelley commented Mar 26, 2024

Here's a slapdash implementation I patched in with yarn patch to my local installation so you can get a sense for what support might look like:

function recursivelyAppendCause(error, indent) {
    if (error) {
        if (error.stack) {
            result += `${indent}[cause]: ${error.stack.split('\n').map(l => `${indent}${l}`).join('\n').replace(/^\s*/, '')}\n`;
        } else {
            result += `${indent}[cause]: [non-error object]\n${error}\n`;
        }
        recursivelyAppendCause(error.cause, indent + '  ');
    }
}

recursivelyAppendCause(error.cause, '  ');

(in Cli#error).

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

No branches or pull requests

1 participant