feat: collect errors from the browser#20487
Conversation
sapphi-red
left a comment
There was a problem hiding this comment.
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
- 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 |
| } | ||
|
|
||
| // error handler | ||
| middlewares.use(errorMiddleware(server, !!middlewareMode)) |
There was a problem hiding this comment.
This removal was accidental, will fix it!
|
ideally the location logged on the terminal console uses |
|
+1 to using the websocket, that would also get rid of the body-parser dependency. |
| try { | ||
| new Function('throw new Error(1)')() | ||
| } catch (e) { | ||
| // in Node 12, stack traces account for the function wrapper. |
There was a problem hiding this comment.
i don't think we have to support node12 here, our engine field asks for 20.19+
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. |
This adds a browser error handler and associated error formatting.
There's on unsolved issue though: when accessing
transformResult, it seemsmapis alwaysnull.