From 561cd9971905a799fe26d94f9959d23ded7111f7 Mon Sep 17 00:00:00 2001 From: Sergey Golitsynskiy Date: Mon, 1 Feb 2021 22:05:06 -0500 Subject: [PATCH] Improve error handling; modify exception ReferenceDataError is more appropriate than MissingDataError --- lib/galaxy/exceptions/__init__.py | 4 ++-- lib/galaxy/exceptions/error_codes.json | 4 ++-- lib/galaxy/visualization/genomes.py | 13 ++++++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/galaxy/exceptions/__init__.py b/lib/galaxy/exceptions/__init__.py index 34c02448e14..c79d1f9c8c6 100644 --- a/lib/galaxy/exceptions/__init__.py +++ b/lib/galaxy/exceptions/__init__.py @@ -221,9 +221,9 @@ class InvalidFileFormatError(MessageException): err_code = error_codes_by_name['INVALID_FILE_FORMAT'] -class MissingDataError(MessageException): +class ReferenceDataError(MessageException): status_code = 500 - err_code = error_codes_by_name['MISSING_DATA_ERROR'] + err_code = error_codes_by_name['REFERENCE_DATA_ERROR'] # non-web exceptions diff --git a/lib/galaxy/exceptions/error_codes.json b/lib/galaxy/exceptions/error_codes.json index 054f8ee999c..4a746065df1 100644 --- a/lib/galaxy/exceptions/error_codes.json +++ b/lib/galaxy/exceptions/error_codes.json @@ -160,9 +160,9 @@ "message": "File format not supported for this operation." }, { - "name": "MISSING_DATA_ERROR", + "name": "REFERENCE_DATA_ERROR", "code": 500006, - "message": "Data required for program execution is missing." + "message": "Reference data required for program execution failed to load." }, { "name": "NOT_IMPLEMENTED", diff --git a/lib/galaxy/visualization/genomes.py b/lib/galaxy/visualization/genomes.py index b342c78ad9a..1da998bb0df 100644 --- a/lib/galaxy/visualization/genomes.py +++ b/lib/galaxy/visualization/genomes.py @@ -7,7 +7,7 @@ from json import loads from bx.seq.twobit import TwoBitFile from galaxy.exceptions import ( - MissingDataError, + ReferenceDataError, ObjectNotFound, ) from galaxy.util.bunch import Bunch @@ -92,7 +92,7 @@ class Genome: """ # if there's no len_file, there's nothing to return if not self.len_file: - raise MissingDataError(f'len_file not set for {self.key}') + raise ReferenceDataError(f'len_file not set for {self.key}') def check_int(s): if s.isdigit(): @@ -375,7 +375,7 @@ class Genomes: dbkey_user = trans.user if not self.has_reference_data(dbkey, dbkey_user): - return None + raise ReferenceDataError(f"No reference data for {dbkey}") # # Get twobit file with reference data. @@ -395,6 +395,9 @@ class Genomes: twobit_dataset = fasta_dataset.get_converted_dataset(trans, 'twobit') twobit_file_name = twobit_dataset.file_name + return self._get_reference_data() + + def _get_reference_data(): # Read and return reference data. try: with open(twobit_file_name, 'rb') as f: @@ -402,5 +405,5 @@ class Genomes: if chrom in twobit: seq_data = twobit[chrom].get(int(low), int(high)) return GenomeRegion(chrom=chrom, start=low, end=high, sequence=seq_data) - except OSError: - return None + except OSError as e: + raise e()