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

Support for printing error causes #234

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dwoznicki
Copy link

This PR adds support for printing error cause. Causes appear as part of the stack trace, and are checked recursively. For example, the following snippet

const {test} = require("uvu");

test("error cause", () => {
    throw new Error("top level", {cause: new Error("mid level", {cause: new Error("bottom level")})});
});
test.run();

produces the following output

✘   (0 / 1)

   FAIL  "error cause"
    top level

    at Object.handler (/home/danwoz/testo/test/t.js:4:11)
    at Number.runner (/home/danwoz/testo/node_modules/uvu/dist/index.js:88:16)
    at Timeout.exec [as _onTimeout] (/home/danwoz/testo/node_modules/uvu/dist/index.js:151:39)

    Caused by: mid level
    at Object.handler (/home/danwoz/testo/test/t.js:4:42)
    at Number.runner (/home/danwoz/testo/node_modules/uvu/dist/index.js:88:16)
    at Timeout.exec [as _onTimeout] (/home/danwoz/testo/node_modules/uvu/dist/index.js:151:39)

    Caused by: bottom level
    at Object.handler (/home/danwoz/testo/test/t.js:4:73)
    at Number.runner (/home/danwoz/testo/node_modules/uvu/dist/index.js:88:16)
    at Timeout.exec [as _onTimeout] (/home/danwoz/testo/node_modules/uvu/dist/index.js:151:39)



  Total:     1
  Passed:    0
  Skipped:   0
  Duration:  2.76ms

Fixes #233

printing is recursive, so arbitrarily deep cause stacks should be
printed.
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.

Error cause not printed
1 participant