Surface invalid theme check config as an error instead of crashing#7868
Draft
PhilippeCollin wants to merge 1 commit into
Draft
Surface invalid theme check config as an error instead of crashing#7868PhilippeCollin wants to merge 1 commit into
PhilippeCollin wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents shopify theme check from crashing when Theme Check configuration resolution/loading fails, and instead surfaces those failures as user-facing AbortErrors (so they’re treated as expected errors and not reported as unhandled bugs).
Changes:
- Added
throwIfThemeCheckConfigErrorto classify known config-loading failures (missing file/dir path, invalid YAML/config) and rethrow them asAbortErrors. - Wrapped
theme checkconfig-loading operations (--print,--list, and the main run) to apply the new config error handling while rethrowing unrelated errors unchanged. - Added unit + integration tests covering the new behavior, plus a changeset for a patch release.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/theme/src/cli/services/check.ts | Adds throwIfThemeCheckConfigError and supporting helpers to convert known config-resolution errors into AbortErrors. |
| packages/theme/src/cli/services/check.test.ts | Adds unit tests for throwIfThemeCheckConfigError and adjusts output mocking to preserve other exports. |
| packages/theme/src/cli/commands/theme/check.ts | Wraps config-related operations in runWithConfigErrorHandling so config failures surface as AbortErrors instead of unhandled exceptions. |
| packages/theme/src/cli/commands/theme/check.test.ts | Adds integration tests verifying missing/malformed configs become AbortErrors and unrelated errors still propagate. |
| .changeset/theme-check-config-errors.md | Declares a patch changeset describing the improved error surfacing for invalid Theme Check configs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f015346 to
d500c04
Compare
d500c04 to
7d2ec0e
Compare
`theme check` resolves the Theme Check configuration through `themeCheckRun` (and `loadConfig` for `--print`/`--list`). theme-check-node raises a typed `ThemeCheckConfigError` for a missing, unreadable, or malformed configuration, so the command recognizes a configuration problem with a single `instanceof` check and surfaces a clear AbortError (shown to the user, not reported as an unexpected crash). Errors from later phases are rethrown unchanged, so genuine bugs are still reported. Assisted-By: devx/e547eed5-2a6b-4b20-972a-c6fe290bdf0c
7d2ec0e to
7d5d761
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WHY are these changes introduced?
shopify theme checkcrashes with an unhandled error when its configuration can't be loaded:theme checkpasses the--configvalue (or a discovered.theme-check.yml) straight into@shopify/theme-check-node's config loader with no error handling, so any config-loading failure escapes as an unexpected crash instead of an actionable message. The same root cause covers a whole class of failures: missing file, inline config string where a path is expected, empty--config, a directory (EISDIR), and malformed YAML. These are configuration problems, not CLI bugs.What is happening?
A new
loadThemeCheckConfighelper wrapsloadConfigand turns any config-loading failure into a user-facingAbortError(shown to the user, not reported as a bug). Config loading is a single, well-defined step — the first thingthemeCheckRundoes, and what--print/--listalready call — so a failure there is by definition a config problem; no error-message parsing needed. The fs errorcode(ENOENT/EISDIR) only refines the message:The Theme Check configuration file couldn't be found: <path>.The Theme Check configuration path is a directory, not a file: <path>.The Theme Check configuration is invalid.(with the underlying detail)…each with a hint to pass a valid
.theme-check.ymlor a preset liketheme-check:recommended. Later phases (globbing, parsing, the checks) aren't caught here, so genuine bugs still report.How to test your changes?
shopify theme check --config ./does-not-exist.yml→ clear "couldn't be found" message (was a crash).shopify theme check --config <a directory>→ clear "not a file" message..theme-check.ymlwith an invalid shape → clear "configuration is invalid" message.Tests
describeThemeCheckConfigError(missing file, directory, other failure, non-Errorvalue) andloadThemeCheckConfig(resolves on success; wraps any failure inAbortError).theme checksurfaces a missing/malformed config asAbortError, and an error from the check phase still propagates unchanged.