Skip to content

Commit

Permalink
Fix error stacktrace from Vite SSR runtime (#7273)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Jun 27, 2023
1 parent 8301679 commit 6dfd708
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-onions-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix error stacktrace from Vite SSR runtime
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-astro-postprocess/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function astro(_opts: AstroPluginOptions): Plugin {
if (s) {
return {
code: s.toString(),
map: s.generateMap(),
map: s.generateMap({ hires: true }),
};
}
},
Expand Down
6 changes: 6 additions & 0 deletions packages/astro/src/vite-plugin-astro-server/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ export async function handleRequest(
},
onError(_err) {
const err = createSafeError(_err);

// This could be a runtime error from Vite's SSR module, so try to fix it here
try {
env.loader.fixStacktrace(err as Error);
} catch {}

// This is our last line of defense regarding errors where we still might have some information about the request
// Our error should already be complete, but let's try to add a bit more through some guesswork
const errorWithMetadata = collectErrorMetadata(err, config.root);
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export default function envVitePlugin({ settings }: EnvPluginOptions): vite.Plug
if (s) {
return {
code: s.toString(),
map: s.generateMap(),
map: s.generateMap({ hires: true }),
};
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-scripts/page-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function astroScriptsPostPlugin({

return {
code: s.toString(),
map: s.generateMap(),
map: s.generateMap({ hires: true }),
};
},
};
Expand Down

0 comments on commit 6dfd708

Please sign in to comment.