invidious icon indicating copy to clipboard operation
invidious copied to clipboard

Add proper exception handling for comments, rather than sliently failing

Open techmetx11 opened this issue 2 years ago • 4 comments

techmetx11 avatar Apr 26 '23 20:04 techmetx11

DO NOT PUSH, I left in the test exception

techmetx11 avatar Apr 26 '23 20:04 techmetx11

As your function share all of it's code with error_template_helper, what I'd recommend you to do is to rename it so something more explicit (like error_template_message) and reuse it in error_template_helper like so:

def error_template_helper(env : HTTP::Server::Context, status_code : Int32, exception : Exception)
  if exception.is_a?(InfoException)
    return error_template_helper(env, status_code, exception.message || "")
  end

  locale = env.get("preferences").as(Preferences).locale

  env.response.content_type = "text/html"
  env.response.status_code = status_code

  error_message = error_template_message(env, exception)

  # Don't show the usual "next steps" widget. The same options are
  # proposed above the error message, just worded differently.
  next_steps = ""

  return templated "error"
end

Thanks for the suggestion, I just threw this code together lazily. I'm gonna try making it better

techmetx11 avatar Apr 28 '23 19:04 techmetx11

I've rebased your changes to fix merge conflicts!

SamantazFox avatar Jun 01 '23 20:06 SamantazFox

When no comments are found, this exception is raised, and this results in "undefined" to be printed: https://github.com/iv-org/invidious/blob/9cec83c1ffcb03bcfd2d43562528ed290a5546da/src/invidious/comments/youtube.cr#L43

Here is an screenshot: image

SamantazFox avatar Jun 11 '23 14:06 SamantazFox

This pull request has been automatically marked as stale and will be closed in 30 days because it has not had recent activity and is much likely abandoned or outdated. If you think this pull request is still relevant and applicable, you just have to post a comment and it will be unmarked.

github-actions[bot] avatar Jul 29 '23 01:07 github-actions[bot]

Sorry, it took me forever to test :/

So I've deployed that on our test instance to try it out again:

Screenshot

image

Here are two things that needs to be addressed:

  1. The current error template is a lot of text, this doesn't integrate well in the page. A smaller variant might be preferred. As an easy alternative, you could show a simple error message like "comments failed to load" then put the bug report under a foldable section (<details>).

  2. When an error is returned from the comments API, the various "next steps" links shouldn't be present in the HTML (imo, trying to make the right links will be too difficult).

SamantazFox avatar Aug 08 '23 21:08 SamantazFox

This pull request has been automatically marked as stale and will be closed in 30 days because it has not had recent activity and is much likely abandoned or outdated. If you think this pull request is still relevant and applicable, you just have to post a comment and it will be unmarked.

github-actions[bot] avatar Nov 07 '23 01:11 github-actions[bot]