Skip to content

Fix theme check JSON output for offenses without a position - #9041

Merged
isaacroldan merged 1 commit into
mainfrom
torrent/devxg-10-p1-error-code-too-small-minimum-0-type-n
Oct 30, 2026
Merged

isaacroldan merged 1 commit into
mainfrom
torrent/devxg-10-p1-error-code-too-small-minimum-0-type-n

Conversation

@isaacroldan

Copy link
Copy Markdown
Contributor

WHY are these changes introduced?

shopify theme check --json fails when Theme Check reports an offense that it cannot place in the file. Theme Check gives line and character -1 for such an offense, for example when an empty layout/theme.liquid misses {{ content_for_header }}. The JSON projection adds 1 to each position, so the result is 0. The output schema requires one-based positions greater than 0, so the command prints a ZodError ("Number must be greater than 0", path issues, <n>, startRow) instead of the issues.

WHAT is this pull request doing?

It clamps each projected position to at least 1. An offense without a known position now points at the start of the file. The schema and its one-based contract do not change. A regression test covers an offense with -1 positions.

Output before, for a theme with an empty layout/theme.liquid:

{"error":{"type":"bug","message":"[\n  {\n    \"code\": \"too_small\",\n    \"minimum\": 0,\n    ...\n    \"message\": \"Number must be greater than 0\",\n    \"path\": [\n      \"issues\",\n      0,\n      \"startRow\"\n    ]\n  },\n  ..."}}

Output after:

{"valid":false,"issues":[{"filePath":"<dir>/layout/theme.liquid","check":"RequiredLayoutThemeObject","severity":"error","startRow":1,"startColumn":1,"endRow":1,"endColumn":1,"message":"The required object '{{ content_for_header }}' is missing in layout/theme.liquid"},{"filePath":"<dir>/layout/theme.liquid","check":"RequiredLayoutThemeObject","severity":"error","startRow":1,"startColumn":1,"endRow":1,"endColumn":1,"message":"The required object '{{ content_for_layout }}' is missing in layout/theme.liquid"}],"errorCount":2,"warningCount":0,"infoCount":0}

How to manually test your changes?

  1. Create a theme directory with an empty layout file: mkdir -p /tmp/empty-theme/layout && touch /tmp/empty-theme/layout/theme.liquid.
  2. Run pnpm shopify theme check --path /tmp/empty-theme --json.
  3. Check that the command prints two RequiredLayoutThemeObject issues at row 1, column 1, and no ZodError.

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes
  • I've considered analytics changes to measure impact
  • The change is user-facing — I've identified the correct bump type (patch for bug fixes · minor for new features · major for breaking changes) and added a changeset with pnpm changeset add

Theme Check reports line and character -1 for an offense that it cannot
place, for example a missing required object in an empty
layout/theme.liquid. The JSON projection added 1 to these values, which
produced 0, and the strict one-based schema rejected the result. So
`shopify theme check --json` failed with a ZodError instead of printing
the issues.

Clamp each projected position to at least 1, so these offenses point at
the start of the file and the output keeps its one-based contract.

Co-authored-by: isaac.roldan <[email protected]>
@github-actions github-actions Bot added the Area: @shopify/theme @shopify/theme package issues label Oct 29, 2026
@isaacroldan
isaacroldan marked this pull request as ready for review October 29, 2026 12:46
@isaacroldan
isaacroldan requested a review from a team as a code owner October 29, 2026 12:46

@karreiro karreiro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you, @isaacroldan!

@isaacroldan
isaacroldan added this pull request to the merge queue Oct 30, 2026
Merged via the queue into main with commit a25396e Oct 30, 2026
29 of 30 checks passed
@isaacroldan
isaacroldan deleted the torrent/devxg-10-p1-error-code-too-small-minimum-0-type-n branch October 30, 2026 16:26
jplhomer pushed a commit that referenced this pull request Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: @shopify/theme @shopify/theme package issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants