Skip to content

Commit

Permalink
Remove legacy compiler error handling (#5855)
Browse files Browse the repository at this point in the history
* refactor: remove legacy compiler handling

* docs: add hint to unknown compiler error

* feat: add link detection to error overlay

* chore: update compiler

* chore: update compiler issue link

* Update packages/astro/src/core/errors/overlay.ts

Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>

Co-authored-by: Nate Moore <nate@astro.build>
Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 18, 2023
1 parent 39c1daa commit 16dc36a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 32 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-spoons-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Remove legacy compiler error handling
2 changes: 1 addition & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"test:e2e:match": "playwright test -g"
},
"dependencies": {
"@astrojs/compiler": "^0.32.0",
"@astrojs/compiler": "^0.33.0",
"@astrojs/language-server": "^0.28.3",
"@astrojs/markdown-remark": "^2.0.0-beta.2",
"@astrojs/telemetry": "^2.0.0-beta.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/core/errors/errors-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const AstroErrorData = defineErrors({
UnknownCompilerError: {
title: 'Unknown compiler error.',
code: 1000,
hint: 'This is almost always a problem with the Astro compiler, not your code. Please open an issue at https://astro.build/issues/compiler.',
},
// 1xxx and 2xxx codes are reserved for compiler errors and warnings respectively
/**
Expand Down Expand Up @@ -47,7 +48,7 @@ export const AstroErrorData = defineErrors({
* - [Official integrations](https://docs.astro.build/en/guides/integrations-guide/#official-integrations)
* - [Astro.clientAddress](https://docs.astro.build/en/reference/api-reference/#astroclientaddress)
* @description
* The adapter you.'re using unfortunately does not support `Astro.clientAddress`.
* The adapter you're using unfortunately does not support `Astro.clientAddress`.
*/
ClientAddressNotAvailable: {
title: '`Astro.clientAddress` is not available in current adapter.',
Expand Down
9 changes: 9 additions & 0 deletions packages/astro/src/core/errors/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,15 @@ class ErrorOverlay extends HTMLElement {

const el = this.root.querySelector(selector);

if (html) {
// Automatically detect links
text = text.split(' ').map(v => {
if (!v.startsWith('https://')) return v;
if (v.endsWith('.')) return `<a target="_blank" href="${v.slice(0, -1)}">${v.slice(0, -1)}</a>.`
return `<a target="_blank" href="${v}">${v}</a>`
}).join(' ');
}

if (el) {
if (!html) {
el.textContent = text.trim();
Expand Down
26 changes: 0 additions & 26 deletions packages/astro/src/vite-plugin-astro/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,31 +124,5 @@ async function enhanceCompileError({
}
}

// improve compiler errors
if (err.stack && err.stack.includes('wasm-function')) {
const search = new URLSearchParams({
labels: 'compiler',
title: '🐛 BUG: `@astrojs/compiler` panic',
template: '---01-bug-report.yml',
'bug-description': `\`@astrojs/compiler\` encountered an unrecoverable error when compiling the following file.
**${id.replace(fileURLToPath(config.root), '')}**
\`\`\`astro
${source}
\`\`\``,
});
(err as any).url = `https://github.com/withastro/astro/issues/new?${search.toString()}`;
err.message = `Error: Uh oh, the Astro compiler encountered an unrecoverable error!
Please open
a GitHub issue using the link below:
${(err as any).url}`;

if (logging.level !== 'debug') {
// TODO: remove stack replacement when compiler throws better errors
err.stack = ` at ${id}`;
}
}

throw err;
}
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 16dc36a

Please sign in to comment.