Skip to content

Commit 8712986

Browse files
authored
Better text for secondaryFile mismatch warnings. (#734)
1 parent 8f759cc commit 8712986

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

cwltool/checker.py

+24-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Any, Callable, Dict, Generator, Iterable, List, Text, Union, cast
66
import six
77

8-
from schema_salad.sourceline import SourceLine, cmap
8+
from schema_salad.sourceline import SourceLine, cmap, strip_dup_lineno, indent, bullets
99
import schema_salad.validate as validate
1010
from .process import shortname
1111
from .errors import WorkflowException
@@ -153,17 +153,28 @@ def static_checker(workflow_inputs, workflow_outputs, step_inputs, step_outputs)
153153
src = warning.src
154154
sink = warning.sink
155155
linkMerge = warning.linkMerge
156-
msg = SourceLine(src, "type").makeError(
157-
"Source '%s' of type %s may be incompatible"
158-
% (shortname(src["id"]), json.dumps(src["type"]))) + "\n" + \
159-
SourceLine(sink, "type").makeError(
160-
" with sink '%s' of type %s"
161-
% (shortname(sink["id"]), json.dumps(sink["type"])))
162-
if linkMerge:
163-
msg += "\n" + SourceLine(sink).makeError(" source has linkMerge method %s" % linkMerge)
164156
if sink.get("secondaryFiles") and sorted(sink.get("secondaryFiles",[])) != sorted(src.get("secondaryFiles",[])):
165-
msg += "\n" + SourceLine(sink.get("_tool_entry", warning.sink), "secondaryFiles").makeError(" sink '%s' expects secondaryFiles %s" % (shortname(sink["id"]), sink.get("secondaryFiles")))
166-
msg += "\n" + SourceLine(src.get("_tool_entry", warning.src), "secondaryFiles").makeError(" source '%s' has secondaryFiles %s" % (shortname(src["id"]), src.get("secondaryFiles")))
157+
msg1 = "Sink '%s'" % (shortname(sink["id"]))
158+
msg2 = SourceLine(sink.get("_tool_entry", sink), "secondaryFiles").makeError(
159+
"expects secondaryFiles: %s but" % (sink.get("secondaryFiles")))
160+
if "secondaryFiles" in src:
161+
msg3 = SourceLine(src, "secondaryFiles").makeError(
162+
"source '%s' has secondaryFiles %s." % (shortname(src["id"]), src.get("secondaryFiles")))
163+
else:
164+
msg3 = SourceLine(src, "id").makeError(
165+
"source '%s' does not include secondaryFiles." % (shortname(src["id"])))
166+
msg4 = SourceLine(src, "id").makeError("To fix, add secondaryFiles: %s to definition of '%s'." % (sink.get("secondaryFiles"), shortname(src["id"])))
167+
msg = SourceLine(sink).makeError("%s\n%s" % (msg1, bullets([msg2, msg3, msg4], " ")))
168+
else:
169+
msg = SourceLine(src, "type").makeError(
170+
"Source '%s' of type %s may be incompatible"
171+
% (shortname(src["id"]), json.dumps(src["type"]))) + "\n" + \
172+
SourceLine(sink, "type").makeError(
173+
" with sink '%s' of type %s"
174+
% (shortname(sink["id"]), json.dumps(sink["type"])))
175+
if linkMerge:
176+
msg += "\n" + SourceLine(sink).makeError(" source has linkMerge method %s" % linkMerge)
177+
167178
warning_msgs.append(msg)
168179
for exception in exceptions:
169180
src = exception.src
@@ -187,8 +198,8 @@ def static_checker(workflow_inputs, workflow_outputs, step_inputs, step_outputs)
187198
% shortname(sink["id"]))
188199
exception_msgs.append(msg)
189200

190-
all_warning_msg = "\n".join(warning_msgs)
191-
all_exception_msg = "\n".join(exception_msgs)
201+
all_warning_msg = strip_dup_lineno("\n".join(warning_msgs))
202+
all_exception_msg = strip_dup_lineno("\n".join(exception_msgs))
192203

193204
if warnings:
194205
_logger.warning("Workflow checker warning:\n%s" % all_warning_msg)

0 commit comments

Comments
 (0)