All Projects → albertz → py_better_exchook

albertz / py_better_exchook

Licence: BSD-2-Clause license
nice Python exception hook replacement

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to py better exchook

madbomber
Backtrace-on-throw C++ exception logger
Stars: ✭ 17 (-51.43%)
Mutual labels:  stacktrace, debugging
Clarify
Remove nodecore related stack trace noise
Stars: ✭ 140 (+300%)
Mutual labels:  stacktrace, debugging
tracehash
Compress long exception traces down to short signatures
Stars: ✭ 20 (-42.86%)
Mutual labels:  stacktrace, debugging
stacktrace
Atom package to navigate stacktraces.
Stars: ✭ 35 (+0%)
Mutual labels:  stacktrace, debugging
Traceback with variables
Adds variables to python traceback. Simple, lightweight, controllable. Debug reasons of exceptions by logging or pretty printing colorful variable contexts for each frame in a stacktrace, showing every value. Dump locals environments after errors to console, files, and loggers. Works in Jupyter and IPython. Install with pip or conda.
Stars: ✭ 509 (+1354.29%)
Mutual labels:  stacktrace, debugging
gostackparse
Package gostackparse parses goroutines stack traces as produced by panic() or debug.Stack() at ~300 MiB/s.
Stars: ✭ 88 (+151.43%)
Mutual labels:  stacktrace, debugging
ebpfault
A BPF-based syscall fault injector
Stars: ✭ 65 (+85.71%)
Mutual labels:  debugging
windbgtree
A command tree based on commands and extensions for Windows Kernel Debugging.
Stars: ✭ 94 (+168.57%)
Mutual labels:  debugging
lua-microscope
Creates images of arbitrary Lua values using GraphViz
Stars: ✭ 31 (-11.43%)
Mutual labels:  debugging
Spelunking
Read definitions of in-memory Mathematica functions with ease
Stars: ✭ 48 (+37.14%)
Mutual labels:  debugging
serverless-lumigo-plugin
Serverless monitoring and troubleshooting plugin to easily apply distributed tracing
Stars: ✭ 59 (+68.57%)
Mutual labels:  debugging
debugconsole
A general-purpose debug console for the Godot Engine.
Stars: ✭ 24 (-31.43%)
Mutual labels:  debugging
Postmortem
A simple debug library for Clojure(Script) that features data-oriented logging and tracing
Stars: ✭ 143 (+308.57%)
Mutual labels:  debugging
omni-trace
Omnipotent/omniscient tracing and debugging for clojure(script)
Stars: ✭ 58 (+65.71%)
Mutual labels:  debugging
Anti-Debugging
A collection of c++ programs that demonstrate common ways to detect the presence of an attached debugger.
Stars: ✭ 297 (+748.57%)
Mutual labels:  debugging
axios-curlirize
axios plugin converting requests to cURL commands, saving and logging them.
Stars: ✭ 152 (+334.29%)
Mutual labels:  debugging
CharlesHack
Hacking Charles Web Debugging Proxy, Working 4.1.4 Version
Stars: ✭ 17 (-51.43%)
Mutual labels:  debugging
clrprint
Print colorful output in the terminal, idle, cmd, and Windows PowerShell using the same functions.
Stars: ✭ 22 (-37.14%)
Mutual labels:  debugging
scope-analyzer
simple scope analysis for javascript ASTs
Stars: ✭ 20 (-42.86%)
Mutual labels:  variables
vil
Vulkan Layer for Live Introspection & Debugging. Allows to view all vulkan state live inside your application.
Stars: ✭ 39 (+11.43%)
Mutual labels:  debugging

better_exchook

A nicer drop-in-replacement for Python sys.excepthook, i.e. it prints stack traces with extended information. It will add some useful information for each frame, like printing the relevant variables (relevant = referenced in the code line). Also see Python source and comments for further details.

Features

  • Shows locals/globals per frame, but only those used in the current statement. It does this by a simple Python code parser.
  • Multi-line Python statements in the stack trace output, in case the statement goes over multiple lines.
  • Shows full function qualified name (not just co_name).
  • Colored/formatted output of each frame.
  • Syntax highlighting for the Python source code.
  • Support for DomTerm, where it folds all the details of each stack frame away by default, and thus provides a much more comprehensive overview, while still providing all the details when needed.

Installation

You can just copy over the single file better_exchook.py to your project.

Or alternatively, it is also available on PyPI and can be installed via:

pip install better_exchook

Usage

import better_exchook
better_exchook.install()  # will just do: sys.excepthook = better_exchook

Examples

Python example code:

try:
    x = {1:2, "a":"b"}
    def f():
        y = "foo"
        x, 42, sys.stdin.__class__, sys.exc_info, y, z
    f()
except Exception:
    better_exchook.better_exchook(*sys.exc_info())

Output:

EXCEPTION
Traceback (most recent call last):
  File "better_exchook.py", line 478, in <module>
    line: f()
    locals:
      f = <local> <function f at 0x107f1de60>
  File "better_exchook.py", line 477, in f
    line: x, 42, sys.stdin.__class__, sys.exc_info, y, z
    locals:
      x = <global> {'a': 'b', 1: 2}
      sys = <global> <module 'sys' (built-in)>
      sys.stdin = <global> <open file '<stdin>', mode 'r' at 0x107d9f0c0>
      sys.stdin.__class__ = <global> <type 'file'>
      sys.exc_info = <global> <built-in function exc_info>
      y = <local> 'foo'
      z = <not found>
NameError: global name 'z' is not defined

Python example code:

try:
    f = lambda x: None
    f(x, y)
except Exception:
    better_exchook.better_exchook(*sys.exc_info())

Output:

EXCEPTION
Traceback (most recent call last):
  File "better_exchook.py", line 484, in <module>
    line: f(x, y)
    locals:
      f = <local> <function <lambda> at 0x107f1df50>
      x = <local> {'a': 'b', 1: 2}
      y = <not found>
NameError: name 'y' is not defined

Python example code:

try:
    (lambda x: None)(__name__,
                     42)  # multiline
except Exception:
    better_exchook.better_exchook(*sys.exc_info())

Output:

EXCEPTION
Traceback (most recent call last):
  File "better_exchook.py", line 490, in <module>
    line: (lambda x: None)(__name__,
                           42)  # multiline
    locals:
      x = <local> {'a': 'b', 1: 2}
      __name__ = <local> '__main__', len = 8
TypeError: <lambda>() takes exactly 1 argument (2 given)

Python example code:

# use this to overwrite the global exception handler
sys.excepthook = better_exchook.better_exchook
# and fail
finalfail(sys)

Output:

EXCEPTION
Traceback (most recent call last):
  File "better_exchook.py", line 497, in <module>
    line: finalfail(sys)
    locals:
      finalfail = <not found>
      sys = <local> <module 'sys' (built-in)>
NameError: name 'finalfail' is not defined

Screenshot:

https://gist.githubusercontent.com/albertz/a4ce78e5ccd037041638777f10b10327/raw/7ec2bb7079dbd56119d498f20905404cb2d812c0/screenshot1.png

Screencast with DomTerm:

https://gist.githubusercontent.com/albertz/a4ce78e5ccd037041638777f10b10327/raw/7ec2bb7079dbd56119d498f20905404cb2d812c0/screencast-domterm.gif

Similar projects

-- Albert Zeyer, <http://www.az2000.de>

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].