-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
feat: forward runtime error logs to server #20916
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
base: main
Are you sure you want to change the base?
feat: forward runtime error logs to server #20916
Conversation
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
commit: |
|
I realized this feature has never had a proper context. This has been raised internally in voidzero as a part of AI coding improvement and I've picked up after #20487. I'll create a proper feature request to accompany with this, but the code here is self-contained and ready for review. |
|
Some thoughts:
|
Yeah or even 'forwardBrowserLogs/Console'? Would it ever not come from a browser? I think just 'error' to start would be good! Log/info could get pretty noisy - could include but default off if it's worth including? |
|
I recommend against using |
|
Thanks for the feedback! We've discussed in the meeting and I updated the description to note some tweaks which I'll do later.
My intent of "runtime" is that to contrast from Vite "plugin" side code (i.e. main Vite node process). Here "runtime" means each Vite environment including ssr and others and we could catch unhandled errors and patch console to do the same thing on ssr, which might run separately from main node process. However, the log and any errors there are usually already visible in the same console for known server environment. We'll adjust option structure and default behavior to take this into account. Also emphasizing the option as
I think we can do this with the options to selectively pick some log levels, something like https://github.com/mitsuhiko/vite-console-forward-plugin?tab=readme-ov-file#usage |
Description
This PR adds
server.forwardRuntimeLogsoption, which enables forwarding unhandled runtime errors from browser to dev server and logs them on terminal.I mostly ported Vitest's error reporting logic and it even bundles a part of
@vitest/utilsfor stack trace parsing (the output below looks so familiar 😄). The code size is expected to be compact and proved to be robust, so I think this approach is fine.I initially implemented in https://github.com/hi-ogawa/reproductions/tree/main/vite-20487-unhandled-error-to-console/runtime-log and userland plugin is possible (though with a caveat that ssr framework requires a way to inject script other than
transformIndexHtml.)TODO
server.forwardRuntimeLogsconsidering the future scope)server.forwardConsole,environment[name].forwardConsole.forwardConsole: boolean : { ... }boolean as simple true/false but additional option to refine specificconsole.xxx.console.error? (e.g.react hydration error is not runtime but only console.errorNo, this wasn't the case.)console.errorshould be picked up as top-levelboolean = truecase as well.process.onlike Vitest)get_errorsMCP endpoint vercel/next.js#84161)Related plugins
vite-plugin-mcpis in this repo)Other bundlers
Example
Example: Github Copilot fixing bug by checking server logs
https://github.com/hi-ogawa/reproductions/tree/main/vite-20916-demo