-
Notifications
You must be signed in to change notification settings - Fork 535
Closed
Milestone
Description
Summary
Apparently, some Exception
classes may not have a .message
attribute. This can be more problematic when catching base Exception
and then trying to log/warn using a string incorporating the original Exception's .message
attribute. Maybe using str(ex)
is more compatible, or more specific exception classes?
Example (from master
):
nipype/nipype/utils/filemanip.py
Lines 866 to 877 in b356ad1
try: | |
proc = sp.Popen( | |
command, stdout=sp.PIPE, stderr=sp.PIPE, shell=True, env=environ | |
) | |
o, e = proc.communicate() | |
deps = o.rstrip() | |
except Exception as ex: | |
deps = '"%s" failed' % command | |
fmlogger.warning( | |
"Could not get dependencies of %s. Error:\n%s", name, ex.message | |
) | |
return deps |
will cause a throw exception if an OSError
is caught, since OSError does not have a .message
attribute (at least in python 3.8.3)
Actual behavior
Python 3.8.3 (default, May 19 2020, 18:47:26)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = OSError('darn')
>>> a.message
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'OSError' object has no attribute 'message'
Expected behavior
>>> str(a)
'darn'
Metadata
Metadata
Assignees
Labels
No labels