Skip to main content

Human readable stacktraces.

Project description

Pretty Traceback

Human readable stacktraces for Python.

Project/Repo:

MIT License Supported Python Versions PyCalVer v202008.0001-alpha PyPI Version PyPI Downloads

Code Quality/CI:

Build Status Type Checked with mypy Code Coverage Code Style: sjfmt

Name role since until
Manuel Barkhau (mbarkhau@gmail.com) author/maintainer 2020-08 -

Overview

Pretty Traceback groups together what belongs together, rather than showing each part of the traceback as if they were all an equally likely source of a bug. This grouping lets you see, what code relates to frameworks or libraries and what code belong to your project, which is of course much more likely to be where the root cause of the issue is.

In other words, get this 😍

/home/user/venvs/py38/bin/myproject
                             <module>                  12: sys.exit(cli())

/home/user/venvs/py38/lib/python3.8/site-packages/
  click/core.py  __call__  829: return self.main(*args, **kwargs)
  click/core.py  main      782: rv = self.invoke(ctx)
  click/core.py  invoke   1259: return _process_result(sub_ctx.command.invoke(sub_ctx))
  click/core.py  invoke   1066: return ctx.invoke(self.callback, **ctx.params)
  click/core.py  invoke    610: return callback(*args, **kwargs)

/home/user/foss/myproject/src/myproject/
  src/myproject/cli.py       build              160: lp_gen_docs.gen_html(built_ctx, html_dir)
  src/myproject/gen_docs.py  gen_html           294: wrapped_html = wrap_content_html(content_html, 'screen', meta, toc)
  src/myproject/gen_docs.py  wrap_content_html  237: result = tmpl.render(**ctx)

/home/user/venvs/py38/lib/python3.8/site-packages/
  jinja2/environment.py  render            1090: self.environment.handle_exception()
  jinja2/environment.py  handle_exception   832: reraise(*rewrite_traceback_stack(source=source))
  jinja2/_compat.py      reraise             28: raise value.with_traceback(tb)

<template>                   top-level template code   56:

TypeError: no loader for this environment specified

Instead of this 🤮

Traceback (most recent call last):
  File "/home/user/venvs/py38/bin/myproject", line 12, in <module>
    sys.exit(cli())
  File "/home/user/venvs/py38/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/user/venvs/py38/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/user/venvs/py38/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/user/venvs/py38/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/user/venvs/py38/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/user/foss/myproject/src/myproject/cli.py", line 148, in build
    lp_gen_docs.gen_html(built_ctx, html_dir)
  File "/home/user/foss/myproject/src/myproject/gen_docs.py", line 295, in gen_html
    wrapped_html = wrap_content_html(content_html, 'screen', meta, toc)
  File "/home/user/foss/myproject/src/myproject/gen_docs.py", line 238, in wrap_content_html
    result = tmpl.render(**ctx)
  File "/home/user/venvs/py38/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/home/user/venvs/py38/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/home/user/venvs/py38/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 56, in top-level template code
TypeError: no loader for this environment specified

Usage

Add the following to your __main__.py or the equivalent module which is your entry point.

try:
    import pretty_traceback
    pretty_traceback.install()
except ImportError:
    pass    # no need to fail because of missing dev dependency

Please do not add this code e.g. to your __init__.py or any other module that your users may import. They may not want you to mess with how their tracebacks are printed.

If you do feel the overwhelming desire to import the pretty_traceback in code that others might import, consider using the envvar argument, which will cause the install function to effectively be a noop unless you set ENABLE_PRETTY_TRACEBACK=1.

try:
    import pretty_traceback
    pretty_traceback.install(envvar='ENABLE_PRETTY_TRACEBACK')
except ImportError:
    pass    # no need to fail because of missing dev dependency

Alternatives

Pretty Traceback is heavilly inspired by the backtrace modile by nir0s.

Changelog for https://gitlab.com/mbarkhau/pretty-traceback

2020.1001

  • Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pretty-traceback-2020.1001.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

pretty_traceback-2020.1001-py2.py3-none-any.whl (7.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pretty-traceback-2020.1001.tar.gz.

File metadata

  • Download URL: pretty-traceback-2020.1001.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.2 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for pretty-traceback-2020.1001.tar.gz
Algorithm Hash digest
SHA256 c5e44c80fac5139fa4e02a5d3d03ad362e5d5c74ac84b5e6e66e1a6adff1a08b
MD5 a9475044086ab5b007e9411a9072db2d
BLAKE2b-256 e9f7bca54fb21680ad5908faa53cc3d21b25f8382debde51b2137adc85905e9e

See more details on using hashes here.

File details

Details for the file pretty_traceback-2020.1001-py2.py3-none-any.whl.

File metadata

  • Download URL: pretty_traceback-2020.1001-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.2 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for pretty_traceback-2020.1001-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a566c280eccb7af44164043553ebeb110bf017420eccc82168158514c1af9d45
MD5 5e6722b9c44d9c04942f2978a747f4ca
BLAKE2b-256 cfc92687ab0554f1b7bd9c1e2a460f089774ac7ea65d3ef173090bdb8e6b5772

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page