Skip to content

FIX: Add informative error for interfaces that fail to return valid runtime object #2692

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

Merged
merged 4 commits into from
Sep 18, 2018

Conversation

effigies
Copy link
Member

@effigies effigies commented Sep 4, 2018

Summary

If an interface has a _run_interface implementation that in some (or all) cases fails to return the passed runtime object, then the error you currently get is:

Traceback (most recent call last):
  File "/usr/local/miniconda/lib/python3.6/site-packages/nipype/pipeline/plugins/multiproc.py", line 69, in run_node
    result['result'] = node.run(updatehash=updatehash)
  File "/usr/local/miniconda/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 471, in run
    result = self._run_interface(execute=True)
  File "/usr/local/miniconda/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 555, in _run_interface
    return self._run_command(execute)
  File "/usr/local/miniconda/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 635, in _run_command
    result = self._interface.run(cwd=outdir)
  File "/usr/local/miniconda/lib/python3.6/site-packages/nipype/interfaces/base/core.py", line 544, in run
    runtime.endTime = dt.isoformat(dt.utcnow())
AttributeError: 'NoneType' object has no attribute 'endTime'

Arising from this chunk of code:

finally:
# This needs to be done always
runtime.endTime = dt.isoformat(dt.utcnow())
timediff = parseutc(runtime.endTime) - parseutc(runtime.startTime)
runtime.duration = (timediff.days * 86400 + timediff.seconds +
timediff.microseconds / 1e6)
results = InterfaceResult(
interface,
runtime,
inputs=inputs,
outputs=outputs,
provenance=None)

This PR simply makes an absent runtime object raise a RuntimeError and give a likely cause.

Acknowledgment

  • (Mandatory) I acknowledge that this contribution will be available under the Apache 2 license.

@effigies effigies added this to the 1.1.3 milestone Sep 4, 2018
@effigies
Copy link
Member Author

Any objections/suggestions here? I'll merge tomorrow AM if nobody minds.

@satra
Copy link
Member

satra commented Sep 17, 2018

while we are at this, should we simply check for None, or actually check that the reserved keywords still exist.

@effigies
Copy link
Member Author

Sorry, could you be more explicit?

@satra
Copy link
Member

satra commented Sep 17, 2018

i.e. that these attributes are still present:

https://github.com/nipy/nipype/blob/master/nipype/interfaces/base/core.py#L492

@effigies
Copy link
Member Author

The easiest way to do that without digging into private variables was to add a Bunch.keys() method. That alright?

@satra
Copy link
Member

satra commented Sep 17, 2018

@effigies - that's fine with me, but for the moment could we keep that api private. ideally we will move away from Bunch to more standard Python objects in Py 3.x.

dict(bunch_var.items()) will return a dict that can be used as well.

so set(dict(bunch_var.items())) == set(dict(orig_runtime.items())) could also work as a check.

where orig_runtime is the pre-call runtime.

@effigies
Copy link
Member Author

Switched to dictcopy, which already exists. We use it elsewhere in the file, so a replace-all when moving to a standard object will catch these additions.

@effigies effigies changed the title FIX: Provide informative error for interfaces that fail to return runtime object FIX: Add informative error for interfaces that fail to return valid runtime object Sep 18, 2018
@effigies effigies merged commit 82121e1 into nipy:master Sep 18, 2018
@effigies effigies deleted the fix/runtime_error branch September 18, 2018 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants