Skip to main content

Pretty error messages

Project description

Pretty Err

A simple library for printing modern, source-annotated error messages.

Features

  • source span annotation
  • color output
  • multiple non-overlapping spans
  • zero-width spans

Install

pip install prettyerr

Example

Say you have the following source code that contains an error

def repeat(message: str, times: int) -> str:
    return message * times

result = repeat("hello", "3")
print(result)

A nice error message might look something like this

Error: type mismatch for argument `times`

    ╭─[path/to/py_example.py:4:10]
  4 | result = repeat("hello", "3")
    ·          ──┬───          ─┬─
    ·            │              ╰─ argument given is type 'str'
    ·            ╰─ `repeat` function's second argument `times` expects an 'int'
    ╰───
  help: Consider changing string literal "3" to integer 3

To render this error message:

from prettyerr import Error, PointerMessage, Span, SrcFile

src = """\
def repeat(message: str, times: int) -> str:
    return message * times

result = repeat("hello", "3")
print(result)
"""

e = Error(
    SrcFile(py_src, "path/to/py_example.py"),
    title="type mismatch for argument `times`",
    pointer_messages=[
        PointerMessage(span=Span(82, 88), message="`repeat` function's second argument `times` expects an 'int'"),
        PointerMessage(span=Span(98, 101), message="argument given is type 'str'"),
    ],
    hint='Consider changing string literal "3" to integer 3',
)
print(e)

Tasks

  • set up slaving to dewy-lang repo error.py
  • set up workflow to periodically check for changes to error.py (maybe once per week?)
    • on change, create a PR using the newest version of the error.py
    • run tests to make sure everything is still working
    • if tests fail, note that in the PR (e.g. if I move error.py, the script would fail to pull it in, etc.)
    • PR should assign me so that I know to deal with it
    • TBD if a previous PR hasn't been merged what to do, perhaps just let it make a new PR?
  • improve README

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

prettyerr-0.0.0.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prettyerr-0.0.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file prettyerr-0.0.0.tar.gz.

File metadata

  • Download URL: prettyerr-0.0.0.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for prettyerr-0.0.0.tar.gz
Algorithm Hash digest
SHA256 6923a0e1f2b64822d579b70005d78ddc455a07a923ad15f5a79dbb9143bc58ba
MD5 f549a5bf4558de3427fb8ebfeaa97cf5
BLAKE2b-256 9cf8da9ecc7dad3219577b213818f0a6357c67d849ff921be10d8a2e7b4207e6

See more details on using hashes here.

File details

Details for the file prettyerr-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: prettyerr-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for prettyerr-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f85b2df0dae6d28426786a6c5bb8c50cd9c70e3d08943b31b511774d42ffe1c0
MD5 49ae17415c969821cc05bbb0d9c9dfaf
BLAKE2b-256 9b12f516234ac58b795f704bd84fb45744922a1fc3cb23749f1f3c7d89df7ea4

See more details on using hashes here.

Supported by

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