feat(wrangler): improve script source display on pretty error screen - #9971
Conversation
🦋 Changeset detectedLatest commit: ae2bbd6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
b690074 to
016388b
Compare
016388b to
f0007b3
Compare
f0007b3 to
e04e371
Compare
There was a problem hiding this comment.
We are now relying on the UserWorker miniflare instance to prettify the error so that we can retrieve the script source from its inspector.
There was a problem hiding this comment.
We will continue stripping this header by default, except on the ProxyWorker miniflare which will pass the header over to the UserWorker miniflare so that user can disable the pretty error screen when needed.
There was a problem hiding this comment.
Youch currently skip displaying the script source if it is an internal module. But we do want it to show up if frame.source is defined. I will put up a PR to youch later.
| return ""; | ||
| } | ||
| - const language = LANGS_MAP[extname(frame.fileName)] ?? "plain"; | ||
| + const language = LANGS_MAP[extname(frame.fileName)] ?? (frame.type === "native" ? "js" : "plain"); |
There was a problem hiding this comment.
Native modules have no extension so there is no syntax highlight by default. But it should be safe to assume native modules to be javascript if available?
| #getEditorLink(ide, frame) { | ||
| const editorURL = EDITORS[ide] || ide; | ||
| - if (!editorURL || frame.type === "native") { | ||
| + if (!editorURL || frame.type === "native" || !existsSync(frame.fileName)) { |
There was a problem hiding this comment.
Not sure if this is a good patch upstream as it assumes youch is running on node environment only. But I will raise it up when I submit a PR to youch.
There was a problem hiding this comment.
Can we make this optional so it can run in non-node environments? We run Youch ourselves in a non-node environment (format-errors), so it would be nice to make that possible without patches (that we apply to format-errors)
| #getEditorLink(ide, frame) { | ||
| const editorURL = EDITORS[ide] || ide; | ||
| - if (!editorURL || frame.type === "native") { | ||
| + if (!editorURL || frame.type === "native" || !existsSync(frame.fileName)) { |
There was a problem hiding this comment.
Can we make this optional so it can run in non-node environments? We run Youch ourselves in a non-node environment (format-errors), so it would be nice to make that possible without patches (that we apply to format-errors)
| #getEditorLink(ide, frame) { | ||
| const editorURL = EDITORS[ide] || ide; | ||
| - if (!editorURL || frame.type === "native") { | ||
| + if (!editorURL || frame.type === "native" || frame.fileType !== 'fs') { |
There was a problem hiding this comment.
We are now relying on the fileType to decide whether Youch should generate a link.
Fixes DEVX-1974
Example screenshots:
Error from native module (Requrie "View All Frames" checked):
Error from missing source file (e.g.
cookie)