Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): improve error handling on missing extracted schema #6204

Merged
merged 5 commits into from
Apr 4, 2024

Conversation

rexxars
Copy link
Member

@rexxars rexxars commented Apr 3, 2024

Description

When you run sanity typegen generate, a fairly common case is that one may have forgotten to run sanity schema extract first. This currently gives a rather unhelpful error (if you're unfamiliar with the setup):

Error: ENOENT: no such file or directory, open './schema.json'

With this PR, I propose that we give a more helpful error if you have not provided even a custom path for the schema:

Error: Schema file not found: ./schema.json - did you run "sanity schema extract"?

I also noticed that using a --config-path flag did not work, only --configPath. To be consistent with other CLI commands, I changed this to allow both forms.

Testing

Added some basic tests to ensure that the different forms work and gives the expected output.

Notes for release

  • Improved error message when extracted schema (from sanity schema extract) could not be found when running sanity typegen generate

@rexxars rexxars requested review from a team as code owners April 3, 2024 23:57
@rexxars rexxars requested review from jtpetty and removed request for a team April 3, 2024 23:57
Copy link

vercel bot commented Apr 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
performance-studio ✅ Ready (Inspect) Visit Preview Apr 4, 2024 5:31pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 4, 2024 5:31pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Apr 4, 2024 5:31pm

Copy link
Contributor

github-actions bot commented Apr 4, 2024

No changes to documentation

Copy link
Contributor

github-actions bot commented Apr 4, 2024

Component Testing Report Updated Apr 4, 2024 5:32 PM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 31s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 6s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 25s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 12s 4 2 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 12s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 32s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 59s 14 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 1s 18 0 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 12s 6 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 13s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 19s 9 0 0

Copy link
Member

@sgulseth sgulseth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the fixes, some feedback, but only 1 critical

packages/@sanity/cli/src/actions/typegen/generateAction.ts Outdated Show resolved Hide resolved
packages/@sanity/cli/test/typegen.test.ts Show resolved Hide resolved
packages/@sanity/cli/src/actions/typegen/generateAction.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@jtpetty jtpetty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @sgulseth 's suggestions but otherwise 👍

@rexxars rexxars added this pull request to the merge queue Apr 4, 2024
Merged via the queue into next with commit 4fb0e66 Apr 4, 2024
36 checks passed
@rexxars rexxars deleted the fix/typegen-cli-hint-on-error branch April 4, 2024 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants