Skip to content

Commit 8c13014

Browse files
fix: ensure that exceptions print storage queries instead of local copies of remote files
1 parent 7a75043 commit 8c13014

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

snakemake/exceptions.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ def __init__(self, rule, lineno=None, snakefile=None):
354354
class AmbiguousRuleException(RuleException):
355355
def __init__(self, filename, job_a, job_b, lineno=None, snakefile=None):
356356
from snakemake import utils
357+
from snakemake.io import pretty_print_iofile
358+
359+
filename = pretty_print_iofile(filename)
357360

358361
wildcards_a = utils.format("{}", job_a._format_wildcards)
359362
wildcards_b = utils.format("{}", job_b._format_wildcards)
@@ -390,10 +393,11 @@ def __init__(self, repeatedrule, file, rule=None):
390393

391394
class MissingRuleException(RuleException):
392395
def __init__(self, file, lineno=None, snakefile=None):
396+
from snakemake.io import pretty_print_iofile
397+
393398
super().__init__(
394-
"No rule to produce {} (if you use input functions make sure that they don't raise unexpected exceptions).".format(
395-
file
396-
),
399+
f"No rule to produce {pretty_print_iofile(file)} (if you use input "
400+
"functions make sure that they don't raise unexpected exceptions).",
397401
lineno=lineno,
398402
snakefile=snakefile,
399403
)
@@ -416,13 +420,17 @@ def __init__(self, lineno=None, snakefile=None):
416420

417421
class IncompleteFilesException(RuleException):
418422
def __init__(self, files):
423+
from snakemake.io import pretty_print_iofile
424+
419425
super().__init__(
420426
"The files below seem to be incomplete. "
421427
"If you are sure that certain files are not incomplete, "
422428
"mark them as complete with\n\n"
423429
" snakemake --cleanup-metadata <filenames>\n\n"
424430
"To re-generate the files rerun your command with the "
425-
"--rerun-incomplete flag.\nIncomplete files:\n{}".format("\n".join(files))
431+
"--rerun-incomplete flag.\nIncomplete files:\n{}".format(
432+
"\n".join(map(pretty_print_iofile, files))
433+
)
426434
)
427435

428436

snakemake/io.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,11 +878,11 @@ def __hash__(self):
878878
return self._file.__hash__()
879879

880880

881-
def pretty_print_iofile(iofile: _IOFile):
882-
if iofile.is_storage:
881+
def pretty_print_iofile(iofile: Union[_IOFile, str]) -> str:
882+
if isinstance(iofile, _IOFile) and iofile.is_storage:
883883
return f"{iofile.storage_object.query} (storage)"
884884
else:
885-
return iofile._file
885+
return iofile
886886

887887

888888
class AnnotatedString(str, AnnotatedStringInterface):

0 commit comments

Comments
 (0)