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

Handle post rendering errors to avoid bricking #3061

Merged
merged 11 commits into from
Oct 14, 2021

Conversation

askvortsov1
Copy link
Sponsor Member

@askvortsov1 askvortsov1 commented Aug 30, 2021

Fixes Part of flarum/issue-archive#85

Changes proposed in this pull request:
Whether it's due to corrupted content, missing tags, caching issues, or other assorted reasons, post content can't be rendered. Currently, this results in an exception that crashes the entire forum and is hard to debug. Instead, we should log the error and show an indicator message that rendering has failed.

Reviewers should focus on:
Is the Formatter class level the best place to do this? I also considered handling it directly under the relevant CommentPost method. The main benefit of handling per-call-site is that we could include some metadata (like the post ID) in the error message. However, we'd need to handle every possible use case, which is expensive and isn't worth it IMO.

Also, any suggestions on better error text?

Screenshots

image

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).

Required changes:

  • Related documentation PR: (Remove if irrelevant)
  • Related core extension PRs: (Remove if irrelevant)

askvortsov1 and others added 3 commits August 30, 2021 16:25
Whether it's due to corrupted content, missing tags, caching issues, or other assorted reasons, post content can't be rendered. Currently, this results in an exception that crashes the entire forum and is hard to debug. Instead, we should log the error and show an indicator message that rendering has failed.
[ci skip] [skip ci]
Copy link
Member

@SychO9 SychO9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! more safe erroring!

I wonder if we could have information on the frontend about the post failing to render so that we can have minimal visuals indicating a formatting failure rather than it looking like an ordinary post. Maybe if we were to add a $renderingFailed property to the comment post model and add that to the serializer ?

@askvortsov1
Copy link
Sponsor Member Author

Yes! more safe erroring!

I wonder if we could have information on the frontend about the post failing to render so that we can have minimal visuals indicating a formatting failure rather than it looking like an ordinary post. Maybe if we were to add a $renderingFailed property to the comment post model and add that to the serializer ?

We could, but that would make the formatter aware of what it's formatting, or require use-case-specific handling. That being said, supporting this is another good reason for moving this handling out of the general formatter and into the serializer.

@SychO9
Copy link
Member

SychO9 commented Aug 30, 2021

Ah I got overexcited and missed the PR description 🙈, I see it now.

Is the Formatter class level the best place to do this? I also considered handling it directly under the relevant CommentPost method. The main benefit of handling per-call-site is that we could include some metadata (like the post ID) in the error message. However, we'd need to handle every possible use case, which is expensive and isn't worth it IMO.

Like I mentioned above, I don't think metadata is needed as much as just a simple boolean value to indicate a rendering failure to the frontend. A simple visual change would be clean and a more efficient indicator of failure alongside the text. So moving this to either the model method or the serializer makes sense.

@askvortsov1
Copy link
Sponsor Member Author

Updated, here's how it looks like now:

image

less/forum/Post.less Outdated Show resolved Hide resolved
askvortsov1 and others added 3 commits October 12, 2021 15:07
Co-authored-by: Sami Mazouz <sychocouldy@gmail.com>
[ci skip] [skip ci]
@SychO9 SychO9 added this to the 1.2 milestone Oct 14, 2021
locale/core.yml Outdated Show resolved Hide resolved
Co-authored-by: David Wheatley <hi@davwheat.dev>
@askvortsov1 askvortsov1 merged commit 60f0ef0 into master Oct 14, 2021
@askvortsov1 askvortsov1 deleted the as/handle-post-rendering-errors branch October 14, 2021 18:30
@SychO9 SychO9 removed this from the 1.2 milestone Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants