Search code examples
pythonpython-3.xerror-handlingsnakemake

Snakemake 'run' directive produces no error message


When I use the run directive in snakemake (using python code) it doesn't produce any kind of error message for troubleshooting. Is this desired behavior? Am I missing something?

Here a minimal example using snakemake 7.8.3 and python 3.9.13. I invoked snakemake with the -p option which in shell directive outputs the exact code as passed to the shell (but doesn't do anything for run directive I guess).

Snakefile:

def useless_function():
    return[thisVariableAlsoDoesntExist]

rule all:
    input: "final.txt"

rule test:
    output: "final.txt"
    run:
        print(thisVariableDoesNotExist)
        useless_function()

Stdout:

Building DAG of jobs...
Using shell: /usr/bin/bash
Provided cores: 1 (use --cores to define parallelism)
Rules claiming more threads will be scaled down.
Job stats:
job      count    min threads    max threads
-----  -------  -------------  -------------
all          1              1              1
test         1              1              1
total        2              1              1

Select jobs to execute...

[Mon Jul 25 18:59:13 2022]
rule test:
    output: final.txt
    jobid: 1
    reason: Missing output files: final.txt
    resources: tmpdir=/tmp

Shutting down, this might take some time.
Exiting because a job execution failed. Look above for error message
Complete log: .snakemake/log/2022-07-25T185913.188760.snakemake.log

Expected error message (when function and print command are executed directly on python console):

>>> print(thisVariableDoesNotExist)
Traceback (most recent call last):                       
  File "<stdin>", line 1, in <module>                    
NameError: name 'thisVariableDoesNotExist' is not defined


>>> useless_function()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in useless_function
NameError: name 'thisVariableAlsoDoesntExist' is not defined

Solution

  • I suspect you are hitting this recent bug https://github.com/snakemake/snakemake/issues/1698.

    If that is the case, you can downgrade to v7.6.2 or work around it, i.e. bear with it or wrap the the code in run in a self-contained script that you execute via shell. This latter is not a bad solution anyway since it keeps the code nicely isolated.