Skip to content

Improve live backup copy error messages - #2988

Open
luismulinari wants to merge 4 commits into
trunkfrom
improve-export-sql-error-messages
Open

Improve live backup copy error messages#2988
luismulinari wants to merge 4 commits into
trunkfrom
improve-export-sql-error-messages

Conversation

@luismulinari

Copy link
Copy Markdown
Contributor

Summary

Surfaces the specific API error message to users during vip export-sql live backup copy, instead of a generic HTTP status message, and adds guardrails for oversized config files.

Previously a failed live backup copy showed:

Error: Error creating live backup copy: Response not successful: Received status code 413

Now it shows the actual reason from the API response body:

Error: Error creating live backup copy: Request body is too large

Changes

  • parseApiError (src/lib/utils.ts): extended to pull the message out of an Apollo ServerError HTTP response body (bodyText), covering both {"status":"error","message":"..."} and GraphQL {"errors":[{"message":"..."}]} payloads. The signature now accepts unknown so callers don't need to cast a caught error. Order: networkErrorgraphQLErrorsbodyTextmessagenull.
  • Live backup copy catch block (src/commands/export-sql.ts): uses parseApiError so the specific API message is shown and tracked.
  • Config size guard: rejects live backup config files larger than 500 KB with a UserError suggesting the --wpcli-command option, avoiding the server-side 413.
  • UserError: config validation failures now throw UserError instead of a generic Error.

Testing

  • Added parseApiError unit tests in __tests__/lib/utils.js covering bodyText message/errors extraction, networkError, graphQLErrors, non-JSON fallback, plain Error, and the null fallback.
  • npx jest __tests__/lib/utils.js — passing.
  • ESLint clean on changed files.

- Extend parseApiError to pull the message out of an Apollo ServerError
  HTTP response body (bodyText), covering both {status,message} and
  GraphQL {errors:[{message}]} payloads, and accept an unknown error so
  callers don't need to cast.
- Use parseApiError in the live backup copy catch block so users see the
  specific API message (e.g. "Request body is too large") instead of a
  generic "Received status code 413".
- Reject live backup config files larger than 500 KB with a UserError
  suggesting the --wpcli-command option.
- Throw UserError instead of Error for config validation failures.
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@luismulinari
luismulinari requested a review from a team July 30, 2026 20:09
Read the config file exactly once with readFileSync and derive existence
(via ENOENT), size, and contents from that single read, instead of
calling existsSync/statSync before readFileSync. This removes the
time-of-check/time-of-use race flagged by CodeQL.
Read the config file once inside a single try/catch instead of the
separate existsSync/statSync checks and nested error handling. Keeps the
CodeQL race-condition fix but with far less branching.
@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant