-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix: violent crash in stack-trace parsing #6407
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
By that logic in can be anything - a function, a number or an array of errors. I'd say the best way to protect the function here is to add a type guard like |
@sheremet-va - thanks for your reply If I wanted to support any type and give special treatment to Array and function, I would do something like: export function parseStacktrace(
stack: string | Array<string> | Function,
options: StackTraceParserOptions = {},
): ParsedStack[] {
const { ignoreStackEntries = stackIgnorePatterns } = options
+ if (typeof stack === 'function') stack = stack();
+ if (Array.isArray(stack)) stack = stack.join('\n');
+ if (typeof stack !== 'string') stack = String(stack);
let stacks = !CHROME_IE_STACK_REGEXP.test(stack)
? parseFFOrSafariStackTrace(stack)
: parseV8Stacktrace(stack) But I failed a build and resorted to new var I need help to understand what happened on But if we're here already - there's another problem with the logic: the regex In one of my attempts, I got this when I tried to return "my" Array as is - which is a filtered array of strings: This result hinted it does not expect an Array of strings, but an array of parsed stackFrames. Anyway. The correction should consider 3 cases - FF_IE/V8/unsupported. To minimize impact on the view/output layer - I can propose that the unsupported case will return an array of one element that displaying it will result in the raw unparsed string propagated to the screen, to give the user ...something. I'm a little reluctant to include such a change in this PR. I can propose to start another after this more urgent fix landed. If we're going for a 2nd PR - I believe I should add tests with it. |
I was saying that we should not support anything other than |
First - wow. you're a fast one. please check it... Anyway - If we don't process anything non-string that would leave the user with no details on screen |
No, that wouldn't be a regression because it doesn't work already. Assuming what users mean if |
Would you please consider the case for a moment? You run a test, you get a fail and you don't get a stack trace. No failed assertion, no stack trace, no reason on screen. I suggest that in that case - a violent crash - as bad as it is - is better, because it gave me a line number I could debug from mu Or am I getting it wrong? Is there a fallback to display with |
Don't patch built-ins if you want to see the stack trace. It's that simple. |
That's what the project requirements are... So what you're saying I can't use |
You can use it, you just won't see the stack trace. |
And not know what the test failed for? If you intend to add a simple string-guard, Edited:
|
🤔 I can propose one more thing - an Im not telling you what to do - you do you, and thanks for all the effort :) I just really do hope we can find a solution for this in the time I have to evaluate the migration from |
df0a330
to
43e26ac
Compare
6a2053c
to
ee72ef3
Compare
hmm. I suspect a flaky one. It passed before I merged changes from the upstream... I also do not understand the error, but would love to treat it if I could |
49e1d69
to
2e21cf9
Compare
Yeah, sorry, the contribution guide is very outdated. There is a discord where you can ask questions: https://chat.vitest.dev/ |
Description
I'm using a module that adds
Error.prototype.toJSON
that represents stack as an array, split by\n
.The purpose is that error stack traces look pretty when spat as JSON and visualized in kibana and it's like.
I'm also use tooling that refine the stack trace more or less like
options.frameFilter
you got in vitest.(There are more benefits, but they are related to the concrete project).
I'm trying to migrate to vitest from mocha, however, when I add a setup file that calls this aforementioned module - I get very violent crashes.
e.g.:

Free your mind. Saying that a variable is of type
string
does not guarantee that it will be a string in runtime... 🤷The proposed fix puts it back to be a string so your normal flow can continue with no interference :)
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yaml
unless you introduce a new test example.Tests
pnpm test:ci
.Documentation
pnpm run docs
command.Changesets
feat:
,fix:
,perf:
,docs:
, orchore:
.