Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: proper error message if resource types do not match (#1556)
  • Loading branch information
johanneskoester committed Apr 1, 2022
1 parent 44aacdb commit 1112321
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
20 changes: 15 additions & 5 deletions snakemake/rules.py
Expand Up @@ -1081,13 +1081,23 @@ def apply(name, res, threads=None):

if not isinstance(res, int) and not isinstance(res, str):
raise WorkflowError(
"Resources function did not return int, float (floats are "
"rouded to the nearest integer), or str.",
f"Resource {name} is neither int, float(would be rounded to nearest int), or str.",
rule=self,
)
if isinstance(res, int):
global_res = self.workflow.global_resources.get(name, res)
if global_res is not None:

global_res = self.workflow.global_resources.get(name)
if global_res is not None:
if not isinstance(res, TBDString) and type(res) != type(global_res):
global_type = (
"an int" if isinstance(global_res, int) else type(global_res)
)
raise WorkflowError(
f"Resource {name} is of type {type(res).__name__} but global resource constraint "
f"defines {global_type} with value {global_res}. "
"Resources with the same name need to have the same types (int, float, or str are allowed).",
rule=self,
)
if isinstance(res, int):
res = min(global_res, res)
return res

Expand Down
22 changes: 22 additions & 0 deletions tests/test_github_issue1389/Snakefile
@@ -0,0 +1,22 @@
rule all:
input:
"test1.txt",
"test2.txt",


rule a:
output:
"test1.txt",
resources:
foo=1,
shell:
"touch {output}"


rule b:
output:
"test2.txt",
resources:
foo="bar",
shell:
"touch {output}"
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions tests/tests.py
Expand Up @@ -1609,3 +1609,8 @@ def test_github_issue1498():

def test_cleanup_metadata_fail():
run(dpath("test09"), cleanup_metadata=["xyz"])


@skip_on_windows # same on win, no need to test
def test_github_issue1389():
run(dpath("test_github_issue1389"), resources={"foo": 4}, shouldfail=True)

0 comments on commit 1112321

Please sign in to comment.