๐ BUG: Astro check silently exists and doesn't report type errors when there are collection schema validation errors
Closed this issue ยท 1 comments
Astro Info
Originally reported on the language-tools repo, which doesn't have this requirement
If this issue only occurs in one browser, which browser is a problem?
N/A
Describe the Bug
Discussed in withastro/language-tools#982
Originally posted by angelikatyborska December 11, 2024
Describe the Bug
astro check
does not finish running and exits silently without reporting any errors when the following conditions are met:
- I'm using
defineCollection
with a schema - I have a file in my collection that has a frontmatter that doesn't confirm to the schema
I have experienced this when I was trying to add typescript to my blog and couldn't figure out why astro check
refuses to do any type validations. I realized what's going on only after I ran astro sync
and fixed collection schema validation errors errors.
I suspect that this bug might affect reporting not only typescript errors, but also other checks that Astro runs.
Steps to Reproduce
npm create astro@latest
using the official blog template (or checkout https://github.com/angelikatyborska/astro-check-bug and skip to step 6)- Install
@astro/check
andtypescript
- Introduce a trivial TS error into one of the
.astro
files, e.g.const foo: string = 3; console.log(foo);
- Run
npm run astro check
and observe that the TS error is reported:angelika in ~/Documents/code/magical-mars (main | โ1) $ npm run astro check 10.9.2 > magical-mars@0.0.1 astro > astro check 18:37:45 [content] Syncing content 18:37:45 [content] Synced content 18:37:45 [types] Generated 260ms 18:37:45 [check] Getting diagnostics for Astro files in /Users/angelika/Documents/code/magical-mars... src/pages/index.astro:7:7 - error ts(2322): Type 'number' is not assignable to type 'string'. 7 const foo: string = 3; ~~~ Result (15 files): - 1 error - 0 warnings - 0 hints
- Introduce a trivial schema error to one of the blog posts, e.g. in
first-post.md
, settitle: 3
(it's supposed to be a string, not a number) - Run
npm run astro check
again and observe no errors of any kind reported, but the process does exit with status 1.angelika in ~/Documents/code/magical-mars (main | โ1) $ npm run astro check 10.9.2 > magical-mars@0.0.1 astro > astro check 18:42:04 [content] Syncing content angelika in ~/Documents/code/magical-mars (main | โ) $ echo $? 1
What I would expect to happen instead, is to see the same errors as I see when I run npm run astro sync
:
angelika in ~/Documents/code/magical-mars (main | โ)
$ npm run astro sync
10.9.2
> magical-mars@0.0.1 astro
> astro sync
18:43:49 [content] Syncing content
[InvalidContentEntryDataError] blog โ first-post data does not match collection schema.
title: Expected type `"string"`, received `"number"`
Hint:
See https://docs.astro.build/en/guides/content-collections/ for more information on content schemas.
Error reference:
https://docs.astro.build/en/reference/errors/invalid-content-entry-data-error/
Location:
/Users/angelika/Documents/code/magical-mars/src/content/blog/first-post.md:0:0
Stack trace:
at getEntryDataAndImages (file:///Users/angelika/Documents/code/magical-mars/node_modules/astro/dist/content/utils.js:163:26)
at async syncData (/Users/angelika/Documents/code/magical-mars/node_modules/astro/dist/content/loaders/glob.js:99:28)
Link to Minimal Reproducible Example
What's the expected result?
For the implicit astro sync
to report schema errors
Link to Minimal Reproducible Example
https://github.com/angelikatyborska/astro-check-bug
Participation
- I am willing to submit a pull request for this issue.
Probably happens because of the try catch at https://github.com/withastro/astro/blob/main/packages/astro/src/cli/check/index.ts#L34-L38