Skip to content

fix: validate --path flag is a directory, not a file#7335

Open
byrichardpowell wants to merge 2 commits intomainfrom
rp/fix-theme-check-path-file-validation
Open

fix: validate --path flag is a directory, not a file#7335
byrichardpowell wants to merge 2 commits intomainfrom
rp/fix-theme-check-path-file-validation

Conversation

@byrichardpowell
Copy link
Copy Markdown
Contributor

Summary

  • Adds isDirectorySync() validation to the --path flag in theme commands
  • Shows a clear error message with a "Did you mean:" suggestion pointing to the parent directory
  • Adds return before process.exit(1) calls for safety when process.exit is mocked in tests

Problem

The --path flag in all theme commands (theme check, theme dev, theme push, etc.) validated that the provided path existed using fileExistsSync(), but did not check whether it was a directory. Since fileExistsSync() returns true for both files and directories, users could pass a file path like sections/foo.liquid and the validation would accept it.

Downstream, @shopify/theme-check-node's loadConfig() calls fs.readdir(root) on the path, which throws ENOTDIR: not a directory, scandir when the path is a file.

Impact: ~490 error events across 220+ affected users in the last 7 days (first seen in CLI 3.93.0).

The errors appear across all platforms (macOS, Windows, Linux) and affect many different theme files (sections/*.liquid, snippets/*.liquid, templates/*.json, blocks/*.liquid, locales/*.json). The likely cause is IDE integrations or editor tasks that pass the currently open file as the --path argument.

Related issue: https://github.com/shop/issues/issues/33774
Observe dashboard: https://observe.shopify.io/a/observe/errors/13708469716602397840

Test plan

  • New test: verifies error message when a file path is passed to --path
  • Existing test: verifies error message when a non-existent path is passed
  • Existing test: verifies directory paths are accepted
  • All 565 theme tests pass (58 test files)
  • check.test.ts tests pass (these mock process.exit and use fake paths)
  • Lint and type checks pass

🤖 Generated with Claude Code

The --path flag in theme commands only checked that the path existed
using fileExistsSync(), which returns true for both files and
directories. When users passed a file path (e.g. sections/foo.liquid),
the downstream theme-check-node code would call readdir() on it and
crash with ENOTDIR.

This was causing ~490 errors across 220+ users in the last 7 days.

The fix adds an isDirectorySync() check after the existence check,
with a clear error message that includes a "Did you mean:" suggestion
pointing to the parent directory.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 16, 2026 18:48
@byrichardpowell byrichardpowell requested review from a team as code owners April 16, 2026 18:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves validation for the --path flag in theme commands to prevent passing file paths (which can lead to ENOTDIR errors downstream) and adds/updates tests and release notes.

Changes:

  • Validate that --path exists and is a directory; otherwise render a clearer error (with a parent-directory suggestion) and exit.
  • Add a test covering the “file path provided” case and fix minor test wording typos.
  • Add a changeset documenting the patch release.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/theme/src/cli/flags.ts Adds directory validation and improved error output for invalid --path values.
packages/theme/src/cli/flags.test.ts Adds coverage for passing a file path; fixes test description typos.
.changeset/fix-theme-check-path-file-validation.md Documents the patch change in release notes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/theme/src/cli/flags.ts Outdated
Comment thread packages/theme/src/cli/flags.ts Outdated
Address review feedback — the error body now says "not a directory"
instead of "is a file", which is more accurate for non-directory
path types.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

2 participants