From eb0a7c27bcf1ff727bb359766276d643bd4035d7 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 19 Sep 2022 08:42:40 +0300 Subject: Improve error reporting for no mapping results * wqflask/wqflask/marker_regression/exceptions.py: new NoMappingResultsError exception * wqflask/wqflask/templates/mapping_error.html: reword display of the errors * wqflask/wqflask/views.py: Raise the NoMappingResultsError exception in the case where there are no results for the mapping. --- wqflask/wqflask/marker_regression/exceptions.py | 13 +++++++++++++ wqflask/wqflask/templates/mapping_error.html | 7 ++++++- wqflask/wqflask/views.py | 10 ++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 wqflask/wqflask/marker_regression/exceptions.py diff --git a/wqflask/wqflask/marker_regression/exceptions.py b/wqflask/wqflask/marker_regression/exceptions.py new file mode 100644 index 00000000..8c7e822b --- /dev/null +++ b/wqflask/wqflask/marker_regression/exceptions.py @@ -0,0 +1,13 @@ +"""Mapping Exception classes.""" + +class NoMappingResultsError(Exception): + "Exception to raise if no results are computed." + + def __init__(self, trait, dataset, mapping_method): + self.trait = trait + self.dataset = dataset + self.mapping_method = mapping_method + self.message = ( + f"The mapping of trait '{trait}' from dataset '{dataset}' using " + f"the '{mapping_method}' mapping method returned no results.") + super().__init__(self.message, trait, mapping_method) diff --git a/wqflask/wqflask/templates/mapping_error.html b/wqflask/wqflask/templates/mapping_error.html index 963bf7d6..8364af3c 100644 --- a/wqflask/wqflask/templates/mapping_error.html +++ b/wqflask/wqflask/templates/mapping_error.html @@ -9,7 +9,12 @@ {%if error:%}

The following error was raised

-     {{error.args[0]}}

+

+
Error message
+
{{error.args[0]}}
+
Error Type
+
{{error_type}}
+

Please contact Zach Sloan (zachary.a.sloan@gmail.com) or Arthur Centeno diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index ee0cd582..88dd31ba 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -46,6 +46,7 @@ from wqflask.external_tools import send_to_webgestalt from wqflask.external_tools import send_to_geneweaver from wqflask.comparison_bar_chart import comparison_bar_chart from wqflask.marker_regression import run_mapping +from wqflask.marker_regression.exceptions import NoMappingResultsError from wqflask.marker_regression import display_mapping_results from wqflask.network_graph import network_graph from wqflask.correlation.show_corr_results import set_template_vars @@ -720,10 +721,11 @@ def mapping_results_page(): try: template_vars = run_mapping.RunMapping(start_vars, temp_uuid) if template_vars.no_results: - rendered_template = render_template("mapping_error.html") - return rendered_template - except FileNotFoundError as fnfe: - rendered_template = render_template("mapping_error.html", error=fnfe) + raise NoMappingResultsError( + start_vars["trait_id"], start_vars["dataset"], start_vars["method"]) + except Exception as exc: + rendered_template = render_template( + "mapping_error.html", error=exc, error_type=type(exc).__name__) return rendered_template if not template_vars.pair_scan: -- cgit v1.2.3