diff --git a/lib/galaxy/datatypes/molecules.py b/lib/galaxy/datatypes/molecules.py index a4cc26b549d2..698ebb2ec07a 100644 --- a/lib/galaxy/datatypes/molecules.py +++ b/lib/galaxy/datatypes/molecules.py @@ -1546,8 +1546,12 @@ def sniff_prefix(self, file_prefix: FilePrefix) -> bool: def set_peek(self, dataset: DatasetProtocol, **kwd) -> None: if not dataset.dataset.purged: dataset.peek = get_file_peek(dataset.get_file_name()) - atom_number = int(dataset.peek.split("\n")[1]) - dataset.blurb = f"{atom_number} atoms" + peek_lines = dataset.peek.split("\n") + try: + atom_number = int(peek_lines[1]) + dataset.blurb = f"{atom_number} atoms" + except (ValueError, IndexError): + dataset.blurb = "file does not look like valid GRO file." else: dataset.peek = "file does not exist" dataset.blurb = "file purged from disk" diff --git a/lib/galaxy/jobs/__init__.py b/lib/galaxy/jobs/__init__.py index 084f0e9d62ec..fe3d4995fb4e 100644 --- a/lib/galaxy/jobs/__init__.py +++ b/lib/galaxy/jobs/__init__.py @@ -1786,13 +1786,9 @@ def _finish_dataset(self, output_name, dataset, job, context, final_job_state, r working_directory=self.working_directory, remote_metadata_directory=remote_metadata_directory, ) - line_count = context.get("line_count", None) - try: - # Certain datatype's set_peek methods contain a line_count argument + if final_job_state != job.states.ERROR: + line_count = context.get("line_count", None) dataset.set_peek(line_count=line_count) - except TypeError: - # ... and others don't - dataset.set_peek() else: # Handle purged datasets. dataset.blurb = "empty" diff --git a/lib/galaxy/metadata/set_metadata.py b/lib/galaxy/metadata/set_metadata.py index 237b106d3c7f..8f1f9ea86be9 100644 --- a/lib/galaxy/metadata/set_metadata.py +++ b/lib/galaxy/metadata/set_metadata.py @@ -506,12 +506,7 @@ def set_meta(new_dataset_instance, file_dict): dataset.dataset.uuid = context["uuid"] if not final_job_state == Job.states.ERROR: line_count = context.get("line_count", None) - try: - # Certain datatype's set_peek methods contain a line_count argument - dataset.set_peek(line_count=line_count) - except TypeError: - # ... and others don't - dataset.set_peek() + dataset.set_peek(line_count=line_count) for context_key in TOOL_PROVIDED_JOB_METADATA_KEYS: if context_key in context: context_value = context[context_key] diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 2519eaec39af..172aab242b03 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -4652,8 +4652,16 @@ def get_mime(self): # extension is None return "data" - def set_peek(self, **kwd): - return self.datatype.set_peek(self, **kwd) + def set_peek(self, line_count=None, **kwd): + try: + # Certain datatype's set_peek methods contain a line_count argument + return self.datatype.set_peek(self, line_count=line_count, **kwd) + except TypeError: + # ... and others don't + return self.datatype.set_peek(self, **kwd) + except Exception: + # Never fail peek setting, but do log exception so datatype logic can be fixed + log.exception("Setting peek failed") def init_meta(self, copy_from=None): return self.datatype.init_meta(self, copy_from=copy_from)