-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add file location to errors in build (#5743)
* feat(errors): Add file location where error happened during build for user-generated errors * chore: changeset * fix(errors): Only add information if the error is in a compatible shape * feat(errors): Add hint to throw Error objects instead of other types for better information * test(errors): Add test to make sure errors in build have the error location * chore(lockfile): Update lockfile * chore: misc text fixes
- Loading branch information
1 parent
000d3e6
commit 2a57864
Showing
9 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Add error location during build for user-generated errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { expect } from 'chai'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('Errors information in build', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
|
||
it('includes the file where the error happened', async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/error-build-location', | ||
}); | ||
|
||
let errorContent; | ||
try { | ||
await fixture.build(); | ||
} catch (e) { | ||
errorContent = e; | ||
} | ||
|
||
expect(errorContent.id).to.equal('src/pages/index.astro'); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
packages/astro/test/fixtures/error-build-location/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { defineConfig } from 'astro/config'; | ||
|
||
export default defineConfig({}); |
15 changes: 15 additions & 0 deletions
15
packages/astro/test/fixtures/error-build-location/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "@test/error-non-error", | ||
"version": "0.0.1", | ||
"private": true, | ||
"scripts": { | ||
"dev": "astro dev", | ||
"start": "astro dev", | ||
"build": "astro build", | ||
"preview": "astro preview", | ||
"astro": "astro" | ||
}, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="astro/client" /> |
3 changes: 3 additions & 0 deletions
3
packages/astro/test/fixtures/error-build-location/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
throw new Error("I'm happening in build!") | ||
--- |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.