-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
feat: collect errors from the browser #20487
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
- communication
- I think we can communicate via the HotChannel (e.g.
transport.send({ type: 'clientError' })) instead of a fetch request. This way we can re-use the same code when we send error information from other environments.
- I think we can communicate via the HotChannel (e.g.
- error collection
- I think we should listen the
unhandledrejectionevent as well to catch the unhandled promise rejections.
- I think we should listen the
- codeframe generation
generateCodeFramefunction can be used for the code frame generation.fetch(info.filename)can be probably replaced withmoduleGraph.getModuleByUrl(id).transformResult- [optional] It seems
colnoandlinenocontains the position for the transformed script. I think we need to map that back to the original code. That should be possible by a code similar to.vite/packages/vite/src/node/ssr/ssrStacktrace.ts
Lines 36 to 49 in f20addc
const mod = moduleGraph.getModuleById(id)const rawSourceMap = mod?.transformResult?.mapif (!rawSourceMap) {return input}const traced = new TraceMap(rawSourceMap as any)const pos = originalPositionFor(traced, {line: Number(line) - offset,// stacktrace's column is 1-indexed, but sourcemap's one is 0-indexedcolumn: Number(column) - 1,}) - I think we can remove the code highlight feature for the following reasons:
- Since this feature is mainly for LLMs, it doesn't help much.
- We don't have that in other places.
@shijikijs/cliis huge and will made Vite's install size to be 1.5x.
We also need a new option server.streamBrowserErrorsToConsole so that this is an opt-in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This removal was accidental, will fix it!
ideally the location logged on the terminal console uses file:///path/to/src/some/cause.js:1:3 style so that users can click on it in their ide powered terminal open that directly. It might also work with relative ./src/some/cause.js:1:3 from cwd to avoid including the full path (esp useful if the user feeds this output to some llm thing or copy&pastes this somewhere public)
+1 to using the websocket, that would also get rid of the body-parser dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think we have to support node12 here, our engine field asks for 20.19+
@shijikijs/cliis huge and will made Vite's install size to be 1.5x.
As a note, Vitest uses tinyhighlight that does the job well enough and is very small. I made it to support colors in error traces, but didn't want to have a huge library. So far, we had no complaints.
Uh oh!
There was an error while loading. Please reload this page.
This adds a browser error handler and associated error formatting.
Screenshot 2025年08月03日 at 19 24 42There's on unsolved issue though: when accessing
transformResult, it seemsmapis alwaysnull.