Skip to content

Fall back to bundled schemas when the remote schema download fails - #519

Merged
swissspidy merged 3 commits into
mainfrom
claude/wp-cli-i18n-518-fix-kd34rn
Nov 3, 2026
Merged

swissspidy merged 3 commits into
mainfrom
claude/wp-cli-i18n-518-fix-kd34rn

Conversation

@swissspidy

@swissspidy swissspidy commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Fixes #518.

JsonSchemaExtractor::remote_get() passes halt_on_error => false to WP_CLI\Utils\http_request() and expects an empty string on failure, so the bundled block-i18n.json / theme-i18n.json copies are used. But on transport errors http_request() throws a RuntimeException even when halt_on_error is false, which aborted make-pot without writing a POT file.

This PR catches that exception in remote_get(), logs a debug message, and returns '' so the existing fallback runs.

Verification

Ran wp i18n make-pot on a plugin with a block.json and theme.json, both with requests forced through an unreachable proxy and with a mocked malformed response:

  • Before: Error: Failed to get url 'https://develop.svn.wordpress.org/trunk/src/wp-includes/block-i18n.json': …, exit 1, no POT.
  • After: debug Failed to download from URL … / Remote file could not be accessed, will use local file as fallback, Success: POT file successfully generated., and the POT contains the block title and theme.json color-name strings.

Tests

Added a Behat scenario in features/makepot.feature that uses the wp-cli-tests Given that HTTP requests to … will respond with: step. The mocked response has no header/body separator, so Requests throws and http_request() raises the same RuntimeException as on a network error. A well-formed error response (e.g. a 500) would not cover this, since it takes the already-working ! $response->success branch. The scenario fails without the fix and needs no network access.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UWTd5ocijEgHN4xLrNgcUG

Summary by CodeRabbit

  • Bug Fixes
    • Translation template generation now completes successfully when remote block or theme schemas are unavailable, using bundled schemas instead.
    • Extracted translations retain the block title “Notice” and theme color name “Black” when network access is unavailable.
    • Remote schema request failures are logged with the URL and error message.

WP_CLI\Utils\http_request() throws a RuntimeException on transport errors
even with halt_on_error set to false, so remote_get() aborted make-pot
instead of returning an empty string and using the bundled
block-i18n.json / theme-i18n.json fallbacks.

Fixes #518.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UWTd5ocijEgHN4xLrNgcUG
Copilot AI balanced review requested due to automatic review settings November 2, 2026 21:59
@swissspidy
swissspidy requested a review from a team as a code owner November 2, 2026 21:59
@swissspidy swissspidy added this to the 3.0.3 milestone Nov 2, 2026 — with Claude
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 775ae9fc-da35-477b-a13f-1e2b3fa73578
Commits

Reviewing files that changed from the base of the PR and between 0b3561a and c54d2f8.

Files selected for processing: 1
  • features/makepot.feature

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Walkthrough

JsonSchemaExtractor now catches RuntimeException from HTTP requests and returns an empty string. A make-pot scenario checks that remote schema failures do not prevent POT generation with bundled schemas.

Changes: Schema download fallback

Layer / File(s) Summary
Handle failed schema downloads
src/JsonSchemaExtractor.php, features/makepot.feature
remote_get catches RuntimeException, logs the URL and exception message, and returns an empty string. The feature scenario checks fallback debug output and POT generation when remote schema downloads return HTTP 503.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: schlessera

Merge Risk: Minimal · up to c54d2

The schema fallback and offline test path are supported, with no actionable merge-blocking risk established.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: using bundled schemas when remote schema downloads fail.
Linked Issues check Passed Issue #518 requires make-pot to handle the transport RuntimeException, log a debug message, return an empty string, and use the bundled schema. src/JsonSchemaExtractor.php imports `RuntimeExcept…
Out of Scope Changes check Passed The production change directly implements issue #518. The features/makepot.feature change is an automated regression test for the remote-schema failure and bundled-schema fallback. No unrelated prod…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check

Explanation

Issue #518 requires make-pot to handle the transport RuntimeException, log a debug message, return an empty string, and use the bundled schema. src/JsonSchemaExtractor.php imports RuntimeException. remote_get() catches it, logs Failed to download from URL ..., and returns ''. load_schema() then logs the fallback message and reads the bundled schema. The added make-pot Behat scenario verifies successful POT generation and extraction from block and theme JSON files under a failed schema request.

Full details: Out of Scope Changes check

Explanation

The production change directly implements issue #518. The features/makepot.feature change is an automated regression test for the remote-schema failure and bundled-schema fallback. No unrelated production behavior or unrelated files are shown in the reviewed changes.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files. (1 skipped: 1 unsupported.)

Finishing Touches
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

Copilot AI 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.

Copilot code review could not start because the generated Actions workflow failed validation. Check .github/workflows/copilot-code-review.yml (or .yaml) on your default branch, or copilot-setup-steps.yml (or .yaml) if the code review workflow is absent. Check action references and the placement of workflow settings. If the configuration is valid, or you have no setup workflow, contact GitHub Support.

@github-actions github-actions Bot added bug command:i18n-make-pot Related to 'i18n make-pot' command scope:testing Related to testing labels Nov 2, 2026
@codecov

codecov Bot commented Nov 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot 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.

  • Fix comments: Fix CodeRabbit comments on this PR

Comment thread features/makepot.feature Resolved
cURL ignores the configured proxy for hosts matched by NO_PROXY/no_proxy,
so an inherited NO_PROXY=* would let the schema downloads succeed and
break the scenario's assertions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UWTd5ocijEgHN4xLrNgcUG
Replace the unreachable-proxy require file with the built-in
"Given that HTTP requests to ... will respond with" step. A mocked
response without a header/body separator makes Requests throw, which
http_request() turns into a RuntimeException, so the scenario exercises
the fixed code path without network access, proxy env vars or retries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UWTd5ocijEgHN4xLrNgcUG
@swissspidy
swissspidy merged commit acde309 into main Nov 3, 2026
64 checks passed
@swissspidy
swissspidy deleted the claude/wp-cli-i18n-518-fix-kd34rn branch November 3, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug command:i18n-make-pot Related to 'i18n make-pot' command scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

make-pot fails without network: remote_get() doesn't catch the exception http_request() throws, so the bundled schemas are never used

3 participants