From 37a2edf00a7e3b7f96c846969a3ff00be8de88ee Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Wed, 19 Jan 2022 14:14:54 +0100 Subject: [PATCH] catch sniffing exceptions in handle uploads Co-authored-by: Nicola Soranzo Co-authored-by: Marius van den Beek --- lib/galaxy/datatypes/upload_util.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/galaxy/datatypes/upload_util.py b/lib/galaxy/datatypes/upload_util.py index 963e2bfb96b..c4772c35332 100644 --- a/lib/galaxy/datatypes/upload_util.py +++ b/lib/galaxy/datatypes/upload_util.py @@ -80,9 +80,13 @@ def handle_upload( if requested_ext != 'auto': datatype = registry.get_datatype_by_extension(requested_ext) # Enable sniffer "validate mode" (prevents certain sniffers from disabling themselves) - if check_content and hasattr(datatype, 'sniff') and not datatype.sniff(path): - stdout = ("Warning: The file 'Type' was set to '{ext}' but the file does not appear to be of that" - " type".format(ext=requested_ext)) + if check_content and hasattr(datatype, 'sniff'): + try: + is_of_datatype = datatype.sniff(path) + except Exception: + is_of_datatype = False + if not is_of_datatype: + stdout = f"Warning: The file 'Type' was set to '{requested_ext}' but the file does not appear to be of that type" # Handle unsniffable binaries if is_binary and ext == 'binary':