-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Custom errors get formatted as JSON objects in the console #7745
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
Comments
Yes. Define |
That results in this kind of formatting, which is functional, but leads to poor developer experience: {
tag: 'MY_ERROR',
stackStr: 'Error: error message\n' +
' at throwError (/home/projects/vitest-dev-vitest-659jeds3/test/basic.test.ts:25:11)\n' +
' at eval (/home/projects/vitest-dev-vitest-659jeds3/test/basic.test.ts:28:3)\n' +
' at eval (file:///home/projects/vitest-dev-vitest-659jeds3/node_modules/@vitest/runner/dist/index.js:217:14)\n' +
' at eval (file:///home/projects/vitest-dev-vitest-659jeds3/node_modules/@vitest/runner/dist/index.js:608:28)\n' +
' at eval (file:///home/projects/vitest-dev-vitest-659jeds3/node_modules/@vitest/runner/dist/index.js:99:24)\n' +
' at https://vitestdevvitest659jeds3-lueh.w-credentialless-staticblitz.com/blitz.33edf5bb.js:40:25129\n' +
' at new Promise (<anonymous>)\n' +
' at new Promise (https://vitestdevvitest659jeds3-lueh.w-credentialless-staticblitz.com/blitz.33edf5bb.js:40:25088)\n' +
' at runWithTimeout (file:///home/projects/vitest-dev-vitest-659jeds3/node_modules/@vitest/runner/dist/index.js:76:12)\n' +
' at runTest (file:///home/projects/vitest-dev-vitest-659jeds3/node_modules/@vitest/runner/dist/index.js:1237:17)',
nameStr: 'Error',
expected: 'undefined',
actual: 'undefined',
stacks: [
{
method: 'throwError',
file: '/home/projects/vitest-dev-vitest-659jeds3/test/basic.test.ts',
line: 25,
column: 11
},
{
method: 'eval',
file: '/home/projects/vitest-dev-vitest-659jeds3/test/basic.test.ts',
line: 28,
column: 3
},
{ method: '', file: '/blitz.33edf5bb.js', line: 40, column: 25129 },
{
method: 'new Promise',
file: '/blitz.33edf5bb.js',
line: 40,
column: 25088
}
]
} It's printed as a JS literal, with stack trace repeated 3 times with different formatting. |
You didn't provide the |
Describe the bug
Custom errors that have
toJSON
method, get formatted as JSON-objects in the console.We're overriding
toJSON
to serialize errors that a passed across API-boundaries. The JSON blob emitted isn't easy to read.Is there a way to implement a custom error serializer for vitest?
Console output:
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-659jeds3?file=test%2Fbasic.test.ts,package.json,tsconfig.json&initialPath=__vitest__/
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: