Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializer: Capture and recover from save errors #2618

Merged
merged 1 commit into from
Sep 7, 2017

Conversation

aduth
Copy link
Member

@aduth aduth commented Aug 31, 2017

Related: #2267

This pull request seeks to appropriately recover from unhandled errors occurring during a block's save implementation. Not only does this help prevent a BSOD (blank screen of death), it also preserves the original content of the block in which the error had occurred (same treatment as in an invalid block).

Implementation notes:

The majority of changes are regenerated fixtures, because we now always assign originalContent into the parsed block object, not just when the post is invalid, since we fall back on this content if an error occurs during the save step.

Testing instructions:

You'll need to manually add the Mr. Crashy block registration prior to editor initialization. I recommend at the bottom of editor/index.js:

wp.blocks.registerBlockType( 'myplugin/mr-crashy', { title: 'Mr. Crashy', category: 'common', icon: 'warning', edit() { return ''; }, save() { throw new Error(); } } );
  1. Navigate to Gutenberg > New Post
  2. Add a paragraph block with some text
  3. Add a Mr. Crashy block
  4. Save the post
  5. Refresh the page
  6. Note that the text block saved correctly, and the Mr. Crashy block displays with an error message
  7. More interestingly, if you manually add content between the Mr. Crashy block delimiters (in Text mode) and save the post, note that content is preserved on refreshing and later saving the post again

@aduth aduth added the [Feature] Blocks Overall functionality of blocks label Aug 31, 2017
@codecov
Copy link

codecov bot commented Aug 31, 2017

Codecov Report

Merging #2618 into master will decrease coverage by <.01%.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2618      +/-   ##
==========================================
- Coverage   33.16%   33.15%   -0.01%     
==========================================
  Files         182      182              
  Lines        5530     5540      +10     
  Branches      963      963              
==========================================
+ Hits         1834     1837       +3     
- Misses       3130     3136       +6     
- Partials      566      567       +1
Impacted Files Coverage Δ
editor/modes/visual-editor/block-crash-boundary.js 0% <0%> (ø) ⬆️
editor/modes/visual-editor/block.js 0% <0%> (ø) ⬆️
blocks/api/serializer.js 97.91% <100%> (+0.04%) ⬆️
blocks/api/validation.js 95.16% <100%> (+0.24%) ⬆️
blocks/api/parser.js 98.14% <100%> (-0.04%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f9b7923...740d1ea. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant