-
-
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.
Improve errors for invalid IDs in content collections (#12892)
* Improve error handling for content collection entries where ID isn't a string * Add passthrough to zod schema to still access other properties after validation * Add new test for numbers as IDs, add changeset * Update error for invalid IDs * Update test for new error message * Update .changeset/dry-dragons-shout.md Co-authored-by: Sarah Rainsberger <[email protected]> * Update errors-data.ts to (possibly) fix tests failing * Update errors-data.ts --------- Co-authored-by: Sarah Rainsberger <[email protected]> Co-authored-by: Matt Kane <[email protected]>
- Loading branch information
1 parent
d5fb7a3
commit 8f520f1
Showing
9 changed files
with
139 additions
and
45 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 | ||
--- | ||
|
||
Adds a more descriptive error when a content collection entry has an invalid ID. |
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
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
9 changes: 9 additions & 0 deletions
9
packages/astro/test/fixtures/content-collections-number-id/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,9 @@ | ||
{ | ||
"name": "@test/content-collections-number-id", | ||
"version": "0.0.0", | ||
"private": true, | ||
"type": "module", | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/astro/test/fixtures/content-collections-number-id/src/content.config.ts
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,17 @@ | ||
import { defineCollection, z } from 'astro:content'; | ||
|
||
const data = defineCollection({ | ||
loader: async () => ([ | ||
{ id: 1, title: 'One!' }, | ||
{ id: 2, title: 'Two!' }, | ||
{ id: 3, title: 'Three!' }, | ||
]), | ||
schema: z.object({ | ||
id: z.number(), | ||
title: z.string(), | ||
}), | ||
}); | ||
|
||
export const collections = { | ||
data, | ||
}; |
6 changes: 6 additions & 0 deletions
6
packages/astro/test/fixtures/content-collections-number-id/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,6 @@ | ||
--- | ||
import { getEntry } from 'astro:content'; | ||
const data = await getEntry('blog', 1); | ||
--- | ||
|
||
{JSON.stringify(data)} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.