Skip to main content

errortext

errortext is a Python package to provide error messages for Python exceptions, even if the original message is empty.

As example consider the following function that might fail in different ways:

from errortext import error_text

def do_something(action_to_perform):
    if action_to_perform == "walk":
        print("walking")
    elif action_to_perform == "sleep":
        raise ValueError("must be tired in order to sleep")
    elif action_to_perform == "run":
        raise NotImplementedError("run")
    else:
        assert False

One could use the following code to run this function and print possible error details by using the error message of the exception from str(error):

try:
    do_something(action)
    print(f"Success: done with {action}")
except Exception as error:
    print(f"Error: cannot {action}: {str(error)}")

As you notice, some error will not have any meaningful message:

do_something("sleep") -> cannot sleep: must be tired in order to sleep
do_something("run")   -> cannot run: run
do_something("xxx")   -> cannot xxx:

No change the error handler to:

print(f"Error with error_text: cannot {action}: {error_text(error)}")

The error messages will at least contain some hint at what went wrong:

do_something("sleep") -> cannot sleep: must be tired in order to sleep
do_something("run")   -> cannot run: NotImplementedError: run
do_something("xxx")   -> cannot xxx: AssertionError

Metadata

Release files for errortext 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for errortext 0.1.0
File Interpreter ABI Platform
errortext-0.1.0-py3-none-any.whl Python 3 none any Details

Release files / errortext-0.1.0-py3-none-any.whl

Download URL errortext-0.1.0-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
330ad6ec71f274feccc7483ee3ca3a77a42684f0acc234fe9f0f7da7ec3d631f
BLAKE2b-256 checksum
How to use checksums
b384bc4fa95bf6f994485e1c1241d02e93bb600be66d024e6b4febe0864d749a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.8.11

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page