Merge pull request #1513 from saltycrys/improve-error-message-2

Improve error message 2
This commit is contained in:
TheFrenchGhosty 2020-12-01 16:36:27 +00:00 committed by GitHub
commit ff3b53e34a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View File

@ -64,7 +64,7 @@ HTTP_CHUNK_SIZE = 10485760 # ~10MB
CURRENT_BRANCH = {{ "#{`git branch | sed -n '/* /s///p'`.strip}" }} CURRENT_BRANCH = {{ "#{`git branch | sed -n '/* /s///p'`.strip}" }}
CURRENT_COMMIT = {{ "#{`git rev-list HEAD --max-count=1 --abbrev-commit`.strip}" }} CURRENT_COMMIT = {{ "#{`git rev-list HEAD --max-count=1 --abbrev-commit`.strip}" }}
CURRENT_VERSION = {{ "#{`git describe --tags --abbrev=0`.strip}" }} CURRENT_VERSION = {{ "#{`git log -1 --format=%cs | sed s/-/./g`.strip}" }}
# This is used to determine the `?v=` on the end of file URLs (for cache busting). We # This is used to determine the `?v=` on the end of file URLs (for cache busting). We
# only need to expire modified assets, so we can use this to find the last commit that changes # only need to expire modified assets, so we can use this to find the last commit that changes

View File

@ -10,16 +10,29 @@ macro error_template(*args)
error_template_helper(env, config, locale, {{*args}}) error_template_helper(env, config, locale, {{*args}})
end end
def github_details(summary : String, content : String)
details = %(\n<details>)
details += %(\n<summary>#{summary}</summary>)
details += %(\n<p>)
details += %(\n \n```\n)
details += content.strip
details += %(\n```)
details += %(\n</p>)
details += %(\n</details>)
return HTML.escape(details)
end
def error_template_helper(env : HTTP::Server::Context, config : Config, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception) def error_template_helper(env : HTTP::Server::Context, config : Config, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception)
if exception.is_a?(InfoException) if exception.is_a?(InfoException)
return error_template_helper(env, config, locale, status_code, exception.message || "") return error_template_helper(env, config, locale, status_code, exception.message || "")
end end
env.response.status_code = status_code env.response.status_code = status_code
issue_template = %(Date: `#{Time::Format::ISO_8601_DATE_TIME.format(Time.utc)}`) issue_template = %(Title: `#{exception.message} (#{exception.class})`)
issue_template += %(\nDate: `#{Time::Format::ISO_8601_DATE_TIME.format(Time.utc)}`)
issue_template += %(\nRoute: `#{env.request.resource}`) issue_template += %(\nRoute: `#{env.request.resource}`)
issue_template += %(\nVersion: `#{SOFTWARE["version"]} @ #{SOFTWARE["branch"]}`) issue_template += %(\nVersion: `#{SOFTWARE["version"]} @ #{SOFTWARE["branch"]}`)
# issue_template += %(\nPreferences: ```#{env.get("preferences").as(Preferences).to_json}```) # issue_template += github_details("Preferences", env.get("preferences").as(Preferences).to_pretty_json)
issue_template += %(\nBacktrace: \n```\n#{exception.inspect_with_backtrace}```) issue_template += github_details("Backtrace", exception.inspect_with_backtrace)
error_message = <<-END_HTML error_message = <<-END_HTML
Looks like you've found a bug in Invidious. Please open a new issue Looks like you've found a bug in Invidious. Please open a new issue
<a href="https://github.com/iv-org/invidious/issues">on GitHub</a> <a href="https://github.com/iv-org/invidious/issues">on GitHub</a>