From 80e15b62e6231a6387c13c3dd461a6df6b6f3cd3 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Mon, 3 Jun 2024 19:42:37 +0200 Subject: [PATCH] Remove html parameter from handle_exception --- lib/galaxy/web/framework/middleware/error.py | 68 +++++++++----------- 1 file changed, 29 insertions(+), 39 deletions(-) diff --git a/lib/galaxy/web/framework/middleware/error.py b/lib/galaxy/web/framework/middleware/error.py index 316cfae336fe..06ee98430e14 100644 --- a/lib/galaxy/web/framework/middleware/error.py +++ b/lib/galaxy/web/framework/middleware/error.py @@ -13,10 +13,7 @@ import sys import traceback from io import StringIO -from typing import ( - cast, - Optional, -) +from typing import cast import markupsafe from paste import ( @@ -197,10 +194,9 @@ def exception_handler(self, exc_info, environ) -> str: get_vars = wsgilib.parse_querystring(environ) if dict(get_vars).get(self.xmlhttp_key): simple_html_error = True - rval = handle_exception( + return handle_exception( exc_info, environ["wsgi.errors"], - html=True, debug_mode=self.debug_mode, error_email=self.error_email, error_log=self.error_log, @@ -215,8 +211,6 @@ def exception_handler(self, exc_info, environ) -> str: simple_html_error=simple_html_error, environ=environ, ) - rval = cast(str, rval) # we know handle_exception returns string because html=True - return rval class ResponseStartChecker: @@ -353,7 +347,6 @@ def extraData(self): def handle_exception( exc_info, error_stream, - html: bool = True, debug_mode=False, error_email=None, error_log=None, @@ -367,7 +360,7 @@ def handle_exception( error_message=None, simple_html_error=False, environ=None, -) -> Optional[str]: +) -> str: """ For exception handling outside of a web context @@ -398,54 +391,51 @@ def handle_exception( smtp_use_tls=smtp_use_tls, subject_prefix=error_subject_prefix, ) - rep_err = send_report(rep, exc_data, html=html) + rep_err = send_report(rep, exc_data, html=True) if rep_err: extra_data += rep_err else: reported = True if error_log: rep = reporter.LogReporter(filename=error_log) - rep_err = send_report(rep, exc_data, html=html) + rep_err = send_report(rep, exc_data, html=True) if rep_err: extra_data += rep_err else: reported = True if show_exceptions_in_wsgi_errors: rep = reporter.FileReporter(file=error_stream) - rep_err = send_report(rep, exc_data, html=html) + rep_err = send_report(rep, exc_data, html=True) if rep_err: extra_data += rep_err else: reported = True else: error_stream.write(f"Error - {exc_data.exception_type}: {exc_data.exception_value}\n") - if html: - if debug_mode and simple_html_error: - return_error = formatter.format_html( - exc_data, include_hidden_frames=False, include_reusable=False, show_extra_data=False - ) - reported = True - elif debug_mode and not simple_html_error: - error_html = formatter.format_html(exc_data, include_hidden_frames=True, include_reusable=False) - head_html = formatter.error_css + formatter.hide_display_js - return_error = error_template(head_html, error_html, extra_data) - extra_data = "" - reported = True - else: - msg = ( - error_message - or """ - An error occurred. - """ - ) - extra = "

The error has been logged to our team." - if "sentry_event_id" in environ: - extra += " If you want to contact us about this error, please reference the following

" - extra += f"GURU MEDITATION: #{environ['sentry_event_id']}" - extra += "

" - return_error = error_template("", msg, extra) + if debug_mode and simple_html_error: + return_error = formatter.format_html( + exc_data, include_hidden_frames=False, include_reusable=False, show_extra_data=False + ) + reported = True + elif debug_mode and not simple_html_error: + error_html = formatter.format_html(exc_data, include_hidden_frames=True, include_reusable=False) + head_html = formatter.error_css + formatter.hide_display_js + return_error = error_template(head_html, error_html, extra_data) + extra_data = "" + reported = True else: - return_error = None + msg = ( + error_message + or """ + An error occurred. + """ + ) + extra = "

The error has been logged to our team." + if "sentry_event_id" in environ: + extra += " If you want to contact us about this error, please reference the following

" + extra += f"GURU MEDITATION: #{environ['sentry_event_id']}" + extra += "

" + return_error = error_template("", msg, extra) if not reported and error_stream: err_report = formatter.format_text(exc_data, show_hidden_frames=True) err_report += f"\n{'-' * 60}\n"