Skip to content
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

Cannot call inspect.getinnerframes on Traceback instance #176

Open
Osmose opened this issue Nov 11, 2015 · 3 comments
Open

Cannot call inspect.getinnerframes on Traceback instance #176

Osmose opened this issue Nov 11, 2015 · 3 comments

Comments

@Osmose
Copy link

Osmose commented Nov 11, 2015

ExceptionInfo creates a Traceback instance from the traceback provided by sys.exc_info and then throws the traceback away. This is inconvenient because some tools (in my case, https://github.com/MindscapeHQ/raygun4py/ calls inspect.getinnerframes on the provided traceback) want to inspect the traceback of an error to get info for error reporting, but the Traceback instance cannot be inspected by functions like inspect.getinnerframes.

Either a reference to the original traceback object or somehow subclassing the built-in class would make it a lot easier to plug these errors into error reporting libraries that expect native traceback objects.

@Osmose
Copy link
Author

Osmose commented Nov 11, 2015

CC @jotes

@jotes
Copy link

jotes commented Nov 12, 2015

@Osmose it looks like there's no easy way to inherit "traceback" object. I don't know specifics why this is done that way internally. "inspect" module has function called istraceback which checks if received object is an instance of TracebackType. Unfortunately, i don't know if there's a simple way to create object which inherits traceback "class" from cPython.

There's a lot of ways we could deal with that: monkey patching of inspect module, rewrite some parts of code in raygun4py to use, try to solve this issue somehow in billiard (i believe that @ask could have some neat ideas where we should go with this issue).

@ask
Copy link
Contributor

ask commented Dec 8, 2015

Pickling the raw traceback is way to brittle since it will contain the local variables of every frame, so we
recreate the traceback without the locals.

As @jotes write, inspect.getinnerframes uses inspect.istraceback which hardocdes the type, and
the type it checks for: types.TracebackType, cannot be subclassed for some crazy reason:

>>> class X(types.TracebackType):
...     pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Error when calling the metaclass bases
    type 'traceback' is not an acceptable base type

Unless we would want to copy lots of code from the inspect module, the only way would be to monkey patch inspect.istraceback :(

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

No branches or pull requests

3 participants