Skip to content

GH#883: handle WP_Error array payloads in network-activate error handler#886

Merged
superdav42 merged 1 commit intomainfrom
feature/auto-20260416-003245-gh883
Apr 16, 2026
Merged

GH#883: handle WP_Error array payloads in network-activate error handler#886
superdav42 merged 1 commit intomainfrom
feature/auto-20260416-003245-gh883

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

Summary

Handle WP_Error serialized array payloads in the network-activate AJAX error handler.

When WordPress serializes a WP_Error to JSON via wp_send_json_error(), it can
produce response.data as either:

  • A plain object with a .message property, or
  • An array of error objects (each with a .message property)

The previous handler only covered the plain-object case. This fix adds detection for
the array case (Array.isArray(response.data)), safely extracts the message from
response.data[0].message, and falls back gracefully through:

  1. Array WP_Error payload → response.data[0].message
  2. Object WP_Error payload → response.data.message
  3. Fallback → wu_network_activate.error_message

All missing element/field guards are in place to prevent runtime errors.

Files Changed

  • EDIT: assets/js/network-activate.js:46-54 — updated error message extraction logic

Runtime Testing

  • Risk level: Low (JavaScript error-path only — no new functionality, no data mutation)
  • Verified: ESLint clean (no new violations introduced); logic covers all three payload shapes

Key Decisions

  • Used Array.isArray() check (not instanceof Array) for cross-frame compatibility
  • Guards response.data.length > 0 && response.data[0] && response.data[0].message prevent all runtime errors on sparse/malformed arrays
  • Pre-existing lint warnings (var, alignment spaces, JSDoc tags) are untouched — they predate this PR

Resolves #883


aidevops.sh v3.8.56 plugin for OpenCode v1.4.6 with claude-sonnet-4-6 spent 3m and 4,211 tokens on this as a headless worker.

When a WP_Error is serialized as JSON in an AJAX response, WordPress can
return response.data as an array of error objects rather than a plain
object with a .message property. Previously the error handler only checked
response.data.message, so array-type WP_Error payloads fell through to
the generic fallback message.

Now the handler first checks Array.isArray(response.data) and extracts
the message from the first element (response.data[0].message), then falls
back to response.data.message for plain-object errors, and finally falls
back to wu_network_activate.error_message. Guards are in place for
missing array elements and missing fields to avoid runtime errors.

Resolves #883
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 16, 2026

Warning

Rate limit exceeded

@superdav42 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 30 minutes and 38 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 30 minutes and 38 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1171e2f3-59e8-424c-9230-d1d34f237cc5

📥 Commits

Reviewing files that changed from the base of the PR and between 3d78cfe and 9b2d592.

📒 Files selected for processing (1)
  • assets/js/network-activate.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/auto-20260416-003245-gh883

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@superdav42
Copy link
Copy Markdown
Collaborator Author

Completion Summary

  • What: Handle WP_Error serialized array payloads in network-activate.js error handler — detect Array.isArray(response.data) and extract response.data[0].message before falling back to response.data.message and the default error string
  • Issue: quality-debt: PR #871 review feedback (medium) #883
  • Files changed: assets/js/network-activate.js
  • Testing: ESLint clean (no new violations), logic covers all three payload shapes (array, object, fallback), guards prevent runtime errors on sparse/malformed data
  • Key decisions: Used Array.isArray() for cross-frame safety; all bounds checks in place

@superdav42 superdav42 merged commit d1d7bef into main Apr 16, 2026
10 of 11 checks passed
@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@github-actions
Copy link
Copy Markdown

Performance Test Results

Performance test results for 201ee0f are in 🛎️!

Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown.

URL: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 41 37.80 MB 882.00 ms (+61.50 ms / +7% ) 165.50 ms (+13.00 ms / +8% ) 1066.00 ms (+64.00 ms / +6% ) 2024.00 ms (+100.00 ms / +5% ) 1943.20 ms (+98.20 ms / +5% ) 86.25 ms
1 56 49.03 MB 1063.50 ms (+51.50 ms / +5% ) 163.00 ms (+7.00 ms / +4% ) 1225.50 ms (+57.50 ms / +5% ) 2360.00 ms (+104.00 ms / +4% ) 2270.50 ms (+101.55 ms / +4% ) 90.20 ms (+2.80 ms / +3% )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

quality-debt: PR #871 review feedback (medium)

1 participant