Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent binary log files to crash snakemake execution with show-failed-logs #2827

Merged
merged 2 commits into from Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions snakemake/logging.py
Expand Up @@ -506,6 +506,9 @@ def show_logs(logs):
except FileNotFoundError:
yield f"Logfile {f} not found."
return
except UnicodeDecodeError:
yield f"Logfile {f} is not a text file."
return
lines = content.splitlines()
logfile_header = f"Logfile {f}:"
if not lines:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_issue2826_failed_binary_logs/Snakefile
@@ -0,0 +1,12 @@
rule:
log:
'log.bin'
run:
import pickle
with open(log[0], 'wb') as f:
# Write anything binary to the file
# that cannot be interpreted as unicode
# dumping the log object was an easy way to do this
pickle.dump(log, f)
# make this test fail
a
12 changes: 12 additions & 0 deletions tests/tests.py
Expand Up @@ -616,6 +616,18 @@ def test_dup_out_patterns():
run(dpath("test_dup_out_patterns"), shouldfail=True)


def test_issue2826_failed_binary_logs():
"""Show how a binary log file crushes `show_logs`

The log file in this test is a binary file.
The `show_failed_logs` is activated by default using `run`,
thus `show_logs` will be called at the end of the test.
Thus this test will check if `show_logs` is able to handle
the binary log file.
"""
run(dpath("test_issue2826_failed_binary_logs"), shouldfail=True)


# TODO reactivate once generic cluster executor is properly released
# @skip_on_windows
# def test_restartable_job_cmd_exit_1_no_restart():
Expand Down