Repository navigation
Editorial Notes: Show an error when a Note fails to save - #1131
maheshbohara wants to merge 3 commits into
Conversation
createNote() saved the Note without throwOnError, so a failed request resolved to undefined and the review still reported the suggestions as added. The editor showed "1 suggestion added" with no Note behind it. The save now rejects on failure, and the existing error handling in the full review and the single block review shows the message as an error notice. See WordPress#1130.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1131 +/- ##
==========================================
Coverage 82.11% 82.11%
Complexity 3394 3394
==========================================
Files 136 136
Lines 13178 13178
==========================================
Hits 10821 10821
Misses 2357 2357
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| } | ||
| }, | ||
| // Reject on a failed save so the caller reports the error. | ||
| { throwOnError: true } |
There was a problem hiding this comment.
So the big issue here is this feature can be run individually or on the entire post. When run individually, we do want the request to throw an error on failure. But when run on the whole post, if some blocks succeed and then one fails, the entire thing is rejected and an error shows, even though some blocks were processed successfully. Ideally we collect errors and continue until the end (or use something like Promise.allSettled) and then show the proper messaging (errors and success count, if any)
There was a problem hiding this comment.
Thanks @dkotter, updated in 2ec258c. The full review now uses Promise.allSettled(), so it continues past a failed block and then shows the saved count plus one error notice with the number of blocks that failed. The single block review still shows the error. I added an e2e test for the partial case.
A full review stopped at the first block that failed, so the Notes already saved for other blocks were left without a count and the remaining blocks were never reviewed. The review now goes through every block, reports the suggestions that were saved, and shows one error notice with the number of blocks that failed. The sidebar no longer says "No new suggestions found." when the only reason is that blocks failed. See WordPress#1130.
What?
Closes #1130
Shows an error notice when Editorial Notes cannot save a Note, in place of the "1 suggestion added" success message.
Why?
createNote()calledsaveEntityRecord()withoutthrowOnError. WhenPOST /wp/v2/commentsfailed, the call resolved toundefinedandreviewSingleBlock()still returned the number of suggestions. The editor then showed "1 suggestion added. Save to keep changes." in the snackbar and "1 suggestion added, view those Notes here" in the sidebar, with no Note on the post. Steps and editor state are in #1130.How?
createNote()passes{ throwOnError: true }tosaveEntityRecord(). A failed save now rejects, and thecatchblocks thatrunReview()andreviewBlock()already have show the REST error message as an error notice, the same way they do when the ability request fails.Promise.allSettled(), so one block that fails no longer stops the run. At the end it shows the count of suggestions that were saved, and one error notice with the number of blocks that failed and the first error message, for example "1 block could not be reviewed: Sorry, you are not allowed to create this comment." This also applies when the ability request fails for a block.editorial-notes.spec.js: a failed save in a full review, a failed save in a single block review, and a full review of two blocks where one save fails and the other is kept. They answer the Note request with a 403.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus
Used for: Investigation, implementation, tests, manual testing, and PR wording. I reviewed the changes and the test results, and I take responsibility for the contribution.
Testing Instructions
developthe snackbar reads "1 suggestion added. Save to keep changes."I ran these steps on WordPress 7.1.3 (wp-env, PHP 8.3) in Chrome, with the repo's
tests/e2e-testingplugin mocking the provider response. With two paragraphs and only the first Note save failing, the snackbar reads "1 suggestion added. Save to keep changes.", the error notice reads "1 block could not be reviewed: Sorry, you are not allowed to create this comment.", and one Note is saved. A single block review with the save failing shows the error only.Automated:
npm run test:e2ewas 194 passed and 7 failed. The 7 are in the alt text, bulk summarization, content classification, markdown feeds and slug generation specs, and they fail the same way ondevelopwithout this change in my environment.npm run test:phppasses (1793 tests). No PHP changed, so PHP coverage is unchanged.composer lint, PHPStan,npm run typecheckandnpm run lint:jspass.Screenshots or screencast
Changelog Entry