Skip to content

Commit 734322e

Browse files
authored
Add include_traceback on SourceLine so nested exceptions are not suppressed. (#547)
1 parent 8ea90c0 commit 734322e

File tree

6 files changed

+21
-17
lines changed

6 files changed

+21
-17
lines changed

cwltool/builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def tostr(self, value): # type: (Any) -> Text
207207
def generate_arg(self, binding): # type: (Dict[Text,Any]) -> List[Text]
208208
value = binding.get("datum")
209209
if "valueFrom" in binding:
210-
with SourceLine(binding, "valueFrom", WorkflowException):
210+
with SourceLine(binding, "valueFrom", WorkflowException, _logger.isEnabledFor(logging.DEBUG)):
211211
value = self.do_eval(binding["valueFrom"], context=value)
212212

213213
prefix = binding.get("prefix")

cwltool/draft2tool.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ def rm_pending_output_callback(output_callbacks, jobcachepending,
346346
j.hints = self.hints
347347
j.name = jobname
348348

349-
if _logger.isEnabledFor(logging.DEBUG):
349+
debug = _logger.isEnabledFor(logging.DEBUG)
350+
351+
if debug:
350352
_logger.debug(u"[job %s] initializing from %s%s",
351353
j.name,
352354
self.tool.get("id", ""),
@@ -405,28 +407,28 @@ def rm_pending_output_callback(output_callbacks, jobcachepending,
405407
self.updatePathmap(builder.outdir, builder.pathmapper, l)
406408
visit_class([builder.files, builder.bindings], ("File", "Directory"), _check_adjust)
407409

408-
if _logger.isEnabledFor(logging.DEBUG):
410+
if debug:
409411
_logger.debug(u"[job %s] path mappings is %s", j.name,
410412
json.dumps({p: builder.pathmapper.mapper(p) for p in builder.pathmapper.files()}, indent=4))
411413

412414
if self.tool.get("stdin"):
413-
with SourceLine(self.tool, "stdin", validate.ValidationException):
415+
with SourceLine(self.tool, "stdin", validate.ValidationException, debug):
414416
j.stdin = builder.do_eval(self.tool["stdin"])
415417
reffiles.append({"class": "File", "path": j.stdin})
416418

417419
if self.tool.get("stderr"):
418-
with SourceLine(self.tool, "stderr", validate.ValidationException):
420+
with SourceLine(self.tool, "stderr", validate.ValidationException, debug):
419421
j.stderr = builder.do_eval(self.tool["stderr"])
420422
if os.path.isabs(j.stderr) or ".." in j.stderr:
421423
raise validate.ValidationException("stderr must be a relative path, got '%s'" % j.stderr)
422424

423425
if self.tool.get("stdout"):
424-
with SourceLine(self.tool, "stdout", validate.ValidationException):
426+
with SourceLine(self.tool, "stdout", validate.ValidationException, debug):
425427
j.stdout = builder.do_eval(self.tool["stdout"])
426428
if os.path.isabs(j.stdout) or ".." in j.stdout or not j.stdout:
427429
raise validate.ValidationException("stdout must be a relative path, got '%s'" % j.stdout)
428430

429-
if _logger.isEnabledFor(logging.DEBUG):
431+
if debug:
430432
_logger.debug(u"[job %s] command line bindings is %s", j.name, json.dumps(builder.bindings, indent=4))
431433

432434
dockerReq = self.get_requirement("DockerRequirement")[0]
@@ -505,17 +507,18 @@ def register_reader(f):
505507
def collect_output_ports(self, ports, builder, outdir, compute_checksum=True, jobname="", readers=None):
506508
# type: (Set[Dict[Text, Any]], Builder, Text, bool, Text, Dict[Text, Any]) -> Dict[Text, Union[Text, List[Any], Dict[Text, Any]]]
507509
ret = {} # type: Dict[Text, Union[Text, List[Any], Dict[Text, Any]]]
510+
debug = _logger.isEnabledFor(logging.DEBUG)
508511
try:
509512
fs_access = builder.make_fs_access(outdir)
510513
custom_output = fs_access.join(outdir, "cwl.output.json")
511514
if fs_access.exists(custom_output):
512515
with fs_access.open(custom_output, "r") as f:
513516
ret = json.load(f)
514-
if _logger.isEnabledFor(logging.DEBUG):
517+
if debug:
515518
_logger.debug(u"Raw output from %s: %s", custom_output, json.dumps(ret, indent=4))
516519
else:
517520
for i, port in enumerate(ports):
518-
with SourceLine(ports, i, WorkflowException):
521+
with SourceLine(ports, i, WorkflowException, debug):
519522
fragment = shortname(port["id"])
520523
try:
521524
ret[fragment] = self.collect_output(port, builder, outdir, fs_access,
@@ -554,14 +557,15 @@ def collect_output_ports(self, ports, builder, outdir, compute_checksum=True, jo
554557
def collect_output(self, schema, builder, outdir, fs_access, compute_checksum=True):
555558
# type: (Dict[Text, Any], Builder, Text, StdFsAccess, bool) -> Union[Dict[Text, Any], List[Union[Dict[Text, Any], Text]]]
556559
r = [] # type: List[Any]
560+
debug = _logger.isEnabledFor(logging.DEBUG)
557561
if "outputBinding" in schema:
558562
binding = schema["outputBinding"]
559563
globpatterns = [] # type: List[Text]
560564

561565
revmap = partial(revmap_file, builder, outdir)
562566

563567
if "glob" in binding:
564-
with SourceLine(binding, "glob", WorkflowException):
568+
with SourceLine(binding, "glob", WorkflowException, debug):
565569
for gb in aslist(binding["glob"]):
566570
gb = builder.do_eval(gb)
567571
if gb:
@@ -626,12 +630,12 @@ def collect_output(self, schema, builder, outdir, fs_access, compute_checksum=Tr
626630
single = True
627631

628632
if "outputEval" in binding:
629-
with SourceLine(binding, "outputEval", WorkflowException):
633+
with SourceLine(binding, "outputEval", WorkflowException, debug):
630634
r = builder.do_eval(binding["outputEval"], context=r)
631635

632636
if single:
633637
if not r and not optional:
634-
with SourceLine(binding, "glob", WorkflowException):
638+
with SourceLine(binding, "glob", WorkflowException, debug):
635639
raise WorkflowException("Did not find output file with glob pattern: '{}'".format(globpatterns))
636640
elif not r and optional:
637641
pass
@@ -642,7 +646,7 @@ def collect_output(self, schema, builder, outdir, fs_access, compute_checksum=Tr
642646
r = r[0]
643647

644648
if "secondaryFiles" in schema:
645-
with SourceLine(schema, "secondaryFiles", WorkflowException):
649+
with SourceLine(schema, "secondaryFiles", WorkflowException, debug):
646650
for primary in aslist(r):
647651
if isinstance(primary, dict):
648652
primary.setdefault("secondaryFiles", [])

cwltool/pathmapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def visit(self, obj, stagedir, basedir, copy=False, staged=False):
254254
if "contents" in obj and obj["location"].startswith("_:"):
255255
self._pathmap[obj["location"]] = MapperEnt(obj["contents"], tgt, "CreateFile", staged)
256256
else:
257-
with SourceLine(obj, "location", validate.ValidationException):
257+
with SourceLine(obj, "location", validate.ValidationException, _logger.isEnabledFor(logging.DEBUG)):
258258
deref = ab
259259
if urllib.parse.urlsplit(deref).scheme in ['http','https']:
260260
deref = downloadHttpFile(path)

cwltool/process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def checkFormat(actualFile, inputFormats, ontology):
392392
def fillInDefaults(inputs, job):
393393
# type: (List[Dict[Text, Text]], Dict[Text, Union[Dict[Text, Any], List, Text]]) -> None
394394
for e, inp in enumerate(inputs):
395-
with SourceLine(inputs, e, WorkflowException):
395+
with SourceLine(inputs, e, WorkflowException, _logger.isEnabledFor(logging.DEBUG)):
396396
fieldname = shortname(inp[u"id"])
397397
if job.get(fieldname) is not None:
398398
pass

cwltool/workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def job(self, joborder, output_callback, **kwargs):
449449
del kwargs["outdir"]
450450

451451
for e, i in enumerate(self.tool["inputs"]):
452-
with SourceLine(self.tool["inputs"], e, WorkflowException):
452+
with SourceLine(self.tool["inputs"], e, WorkflowException, _logger.isEnabledFor(logging.DEBUG)):
453453
iid = shortname(i["id"])
454454
if iid in joborder:
455455
self.state[i["id"]] = WorkflowStateItem(i, copy.deepcopy(joborder[iid]), "success")

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
'ruamel.yaml >= 0.12.4, < 0.15',
5454
'rdflib >= 4.2.2, < 4.3.0',
5555
'shellescape >= 3.4.1, < 3.5',
56-
'schema-salad >= 2.6, < 3',
56+
'schema-salad >= 2.6.20170927145003, < 3',
5757
'typing >= 3.5.3',
5858
'six >= 1.8.0',
5959
],

0 commit comments

Comments
 (0)