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
Quickstart
Print out an error report for some example source code
from prettyerr import Error, Pointer, Span, SrcFile
# example source code
src = """\
const repeat = (message:string, times:int) :> string => {
return message * times
}
result = repeat("hello", "3")
printl(result)
"""
# Locate spans to highlight (.index() here is just for simplicity)
repeat_start = src.index('repeat(')
bad_arg_start = src.index('"3"')
times_span = Span(repeat_start, repeat_start + len('repeat'))
bad_arg_span = Span(bad_arg_start, bad_arg_start + len('"3"'))
# Build and print the error report
report = Error(
SrcFile.from_text(src, "path/to/example.lang"),
title="type mismatch for argument `times`",
pointer_messages=[
Pointer(span=times_span, message="`repeat` function's second argument `times` expects an 'int'"),
Pointer(span=bad_arg_span, message="argument given is type 'string'"),
],
hint='Consider changing string literal "3" to integer 3',
)
print(report)
This generates the following error report
Error: type mismatch for argument `times`
╭─[path/to/example.lang:4:10]
4 | result = repeat("hello", "3")
· ──┬─── ─┬─
· │ ╰─ argument given is type 'string'
· ╰─ `repeat` function's second argument `times` expects an 'int'
╰───
help: Consider changing string literal "3" to integer 3
API at a glance
SrcFile.from_text(body, path=None)Span(start, stop)(stop-exclusive)Pointer(span=Span(...) | list[Span], message=..., placement=None, color=None)- Report types:
Error,Warning,Info,Hint - Common fields:
title,message,pointer_messages,hint,use_color
Tips
- Disable ANSI colors with
use_color=False. - Raise an exception with
Error(...).throw()(raisesReportException).
Metadata
Release files for prettyerr 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| prettyerr-0.0.4.tar.gz | 24.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| prettyerr-0.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.8 kB
Release files / prettyerr-0.0.4.tar.gz
| Download URL | prettyerr-0.0.4.tar.gz |
|---|---|
| Size | 24.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d2dbbb25f6a85a758b0325b4c789b51abf5e84f1d63b3313ba7293bf8b55109e
|
|
BLAKE2b-256 checksum How to use checksums |
0d7835d498a709922b4f0508f033f1c90f21dd9a1e69a3119471514f62a66a6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / prettyerr-0.0.4-py3-none-any.whl
| Download URL | prettyerr-0.0.4-py3-none-any.whl |
|---|---|
| Size | 12.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b700699b0f2b2ef85cd1f1cc9d11346ac269df2e79593658330fd6b92867de6c
|
|
BLAKE2b-256 checksum How to use checksums |
140ee65f0480b4bc6e7cc11446b2baf11a313eb5b3f4691bbf9d547eb43265be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|