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
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).
Project details
Release history Release notifications | RSS feed
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.3.tar.gz
(24.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
prettyerr-0.0.3-py3-none-any.whl
(12.8 kB
view details)
File details
Details for the file prettyerr-0.0.3.tar.gz.
File metadata
- Download URL: prettyerr-0.0.3.tar.gz
- Upload date:
- Size: 24.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c8effb1939c8cbf6e382c77227a9397f7d38aef506fb0494708b707fa4d1756
|
|
| MD5 |
ef6be66292369040915c949ab74a1238
|
|
| BLAKE2b-256 |
a41be65fb2b9c7eb82a237066cf2b8b05e1247539baad33afae1be1b6fd676ff
|
File details
Details for the file prettyerr-0.0.3-py3-none-any.whl.
File metadata
- Download URL: prettyerr-0.0.3-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6e531c4d54b10c66047332532efbfb8b17e96ce1de4cfb265266ed75aa7992e
|
|
| MD5 |
9df62c2276a462b4636585e486e78c11
|
|
| BLAKE2b-256 |
b1328cc913d941b7e3a6c553efcf8bcd39f74751c9f7129885a4593e2b2845ca
|