Skip to content
This repository has been archived by the owner on Apr 10, 2021. It is now read-only.

Include cause exception details in RuntimeError #22

Merged
merged 2 commits into from
Oct 30, 2017

Conversation

GlenWalker
Copy link
Contributor

If there is any kind of error when importing monotonic a generic RuntimeError is raised, with the description 'no suitable implementation for this system'. We very occasionally see this on a system where monotonic otherwise works correctly. I suspect ctypes.util.find_library is occasionally failing (as it executes ldconfig under the hood), but it is difficult to tell because details of the cause are lost, and replaced with the generic error message. Include details of the cause exception in the RuntimeError description so this information is not lost.

If there is any kind of error when importing monotonic a generic RuntimeError is raised, with the description 'no suitable implementation for this system'. We very occasionally see this on a system where monotonic otherwise works correctly. I suspect ctypes.util.find_library is occasionally failing (as it executes ldconfig under the hood), but it is difficult to tell because details of the cause are lost, and replaced with the generic error message. Include details of the cause exception in the RuntimeError description so this information is not lost.
Copy link
Owner

@atdt atdt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay.

monotonic.py Outdated
except Exception:
raise RuntimeError('no suitable implementation for this system')
except Exception as e:
raise RuntimeError('no suitable implementation for this system : ' + repr(e))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why repr and not str?

Copy link
Contributor Author

@GlenWalker GlenWalker Jun 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repr typically includes more information in its output than str. For built-in exceptions str will just return the exception message, while repr will also include the exception class name, which would be useful to me when debugging the issue. Since the error I mentioned above happens infrequently I want to gather as much information about the cause exception as possible.

For example:

import ctypes
import ctypes.util
try:
    ctypes.CDLL(ctypes.util.find_library('c')).missing_function
except Exception as e:
  print 'str', str(e)
  print 'repr', repr(e)

outputs

str /lib/x86_64-linux-gnu/libc.so.6: undefined symbol: missing_function
repr AttributeError('/lib/x86_64-linux-gnu/libc.so.6: undefined symbol: missing_function',)

@jeffreydwalter
Copy link
Contributor

I'm neutral on whether or not the exception is a repr or a str, but it definitely needs to log something more than it does currently. While trying to debug #23 I also had to make this same change for the issue to become clear.

Trimmed extra space from exception message
@atdt atdt merged commit b33db51 into atdt:master Oct 30, 2017
@atdt
Copy link
Owner

atdt commented Oct 30, 2017

Thank you. I'll cut a new release in the next couple of days.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants