-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Customize Error Serializer #5487
Comments
Just in case, could you explain what exactly the "issue" is instead of suggesting the "solution" which is supposed to solve that unclarified "issue"? Would it be essentially same as this issue where Vitest's last To understand your request better, we'll need more context and ideally reproductions to illustrate the issue. |
Hello @moroine. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with |
My bad sorry, the problem I'd like to fix is the output is not readable. There is a lot of pollution in the output About the solution proposed, it's mostly because it was requested in the template. An in order to have generic output, we could use
It's not really this issue, I'd like to see all data within the error and keep the same verbosity. The main goal is how to format this data (especially with buffer and function fields).
I've created a reproduction, and you can see in the console for exemple the |
Thanks for the repro. Yeah, I can understand the issue better now. Previously I wasn't even sure if you were talking about Test errors need to be passed from test runner runtime to main process and it requires some serializations: vitest/packages/utils/src/error.ts Lines 29 to 33 in 9dee912
Currently there's no customization possible here, but maybe somehow we can allow users to intercept and customize it. |
I was playing with the reproduction and I found that it already gets weird with FAIL test/suite.test.ts > repro
Error: Failed
❯ eval test/suite.test.ts:4:15
2|
3| it('repro', () => {
4| const err = new Error('Failed');
| ^
5| err.date = new Date()
6| throw err;
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { date: { constructor: 'Function<Date>', toString: 'Function<toString>', toDateString: 'Function<toDateString>', toTimeString: 'Function<toTimeString>', toISOString: 'Function<toISOString>', toUTCString: 'Function<toUTCString>', toGMTString: 'Function<toUTCString>', getDate: 'Function<getDate>', setDate: 'Function<setDate>', getDay: 'Function<getDay>', getFullYear: 'Function<getFullYear>', setFullYear: 'Function<setFullYear>', getHours: 'Function<getHours>', setHours: 'Function<setHours>', getMilliseconds: 'Function<getMilliseconds>', setMilliseconds: 'Function<setMilliseconds>', getMinutes: 'Function<getMinutes>', setMinutes: 'Function<setMinutes>', getMonth: 'Function<getMonth>', setMonth: 'Function<setMonth>', getSeconds: 'Function<getSeconds>', setSeconds: 'Function<setSeconds>', getTime: 'Function<getTime>', setTime: 'Function<setTime>', getTimezoneOffset: 'Function<getTimezoneOffset>', getUTCDate: 'Function<getUTCDate>', setUTCDate: 'Function<setUTCDate>', getUTCDay: 'Function<getUTCDay>', getUTCFullYear: 'Function<getUTCFullYear>', setUTCFullYear: 'Function<setUTCFullYear>', getUTCHours: 'Function<getUTCHours>', setUTCHours: 'Function<setUTCHours>', getUTCMilliseconds: 'Function<getUTCMilliseconds>', setUTCMilliseconds: 'Function<setUTCMilliseconds>', getUTCMinutes: 'Function<getUTCMinutes>', setUTCMinutes: 'Function<setUTCMinutes>', getUTCMonth: 'Function<getUTCMonth>', setUTCMonth: 'Function<setUTCMonth>', getUTCSeconds: 'Function<getUTCSeconds>', setUTCSeconds: 'Function<setUTCSeconds>', valueOf: 'Function<valueOf>', getYear: 'Function<getYear>', setYear: 'Function<setYear>', toJSON: 'Function<toJSON>', toLocaleString: 'Function<toLocaleString>', toLocaleDateString: 'Function<toLocaleDateString>', toLocaleTimeString: 'Function<toLocaleTimeString>' } }
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯ |
Clear and concise description of the problem
I have issue with the default serialized error, especially with MongoError. Here is a sample error output:
Notes:
Show Error
Suggested solution
Being able to customize serialized value of error (here I'd use ObjectId.toString) and strip function names.
Or it could be an option to use
toJSON
when the function is defined in the object.Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: