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.4.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.4-py3-none-any.whl
(12.8 kB
view details)
File details
Details for the file prettyerr-0.0.4.tar.gz.
File metadata
- Download URL: prettyerr-0.0.4.tar.gz
- Upload date:
- Size: 24.9 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2dbbb25f6a85a758b0325b4c789b51abf5e84f1d63b3313ba7293bf8b55109e
|
|
| MD5 |
23ac05c4be3b8c16e54f6dde809e3249
|
|
| BLAKE2b-256 |
0d7835d498a709922b4f0508f033f1c90f21dd9a1e69a3119471514f62a66a6a
|
File details
Details for the file prettyerr-0.0.4-py3-none-any.whl.
File metadata
- Download URL: prettyerr-0.0.4-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b700699b0f2b2ef85cd1f1cc9d11346ac269df2e79593658330fd6b92867de6c
|
|
| MD5 |
632d0939359c3d8ea4baece880211fd9
|
|
| BLAKE2b-256 |
140ee65f0480b4bc6e7cc11446b2baf11a313eb5b3f4691bbf9d547eb43265be
|