Provide error messages for Python exceptions, even if the original message is empty

Overview

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:

cannot sleep: must be tired in order to sleep do_something("run") -> cannot run: run do_something("xxx") -> cannot xxx: ">
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:

cannot sleep: must be tired in order to sleep do_something("run") -> cannot run: NotImplementedError: run do_something("xxx") -> cannot xxx: AssertionError ">
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
You might also like...
UFDR2DIR - A script to convert a Cellebrite UFDR to the original file structure

UFDR2DIR A script to convert a Cellebrite UFDR to it's original file and directo

Tc-python - A Python script to receive message from a twitch chat

Twitch-Chat 📜 I did a script in Python to receive messages from a twitch chat.

This is a Python 3.10 port of mock, a library for manipulating human-readable message strings.

This is a Python 3.10 port of mock, a library for manipulating human-readable message strings.

Run Python code right in your Telegram messages
Run Python code right in your Telegram messages

Run Python code right in your Telegram messages Made with Telethon library, TGPy is a tool for evaluating expressions and Telegram API scripts. Instal

A python tool for synchronizing the messages from different threads, processes, or hosts.

Sync-stream This project is designed for providing the synchoronization of the stdout / stderr among different threads, processes, devices or hosts.

Python tools for working with Orbit Ephemeris Messages (OEMs).

Python Orbit Ephemeris Message tools Python tools for working with Orbit Ephemeris Messages (OEMs). Development Status Installation The oem package is

To check my COVID-19 vaccine appointment, I wrote an infinite loop that sends me a Whatsapp message hourly using Twilio and Selenium. It works on my Raspberry Pi computer.
To check my COVID-19 vaccine appointment, I wrote an infinite loop that sends me a Whatsapp message hourly using Twilio and Selenium. It works on my Raspberry Pi computer.

COVID-19_vaccine_appointment To check my COVID-19 vaccine appointment, I wrote an infinite loop that sends me a Whatsapp message hourly using Twilio a

Check a discord message and give it a percentage of scamminess

scamChecker Check a discord message and give it a percentage of scamminess Run the bot, and run the command !scamCheck and it will return a percentage

Very Simple 2 Message Spammer!

Very Simple 2 Message Spammer!

Owner
Thomas Aglassinger
Thomas Aglassinger
Izy - Python functions and classes that make python even easier than it is

izy Python functions and classes that make it even easier! You will wonder why t

null 5 Jul 4, 2022
Check is a integer is even

Is Even Check if interger is even using isevenapi. https://isevenapi.xyz/ Main features: cache memoization api retry handler hide ads Install pip inst

Rosiney Gomes Pereira 45 Dec 19, 2022
A GUI love Calculator which saves all the User Data in text file(sql based script will be uploaded soon). Interative GUI. Even For Admin Panel

Love-Calculator A GUI love Calculator which saves all the User Data in text file(sql based script will be uploaded soon). Interative GUI, even For Adm

Adithya Krishnan 1 Mar 22, 2022
qecsim is a Python 3 package for simulating quantum error correction using stabilizer codes.

qecsim qecsim is a Python 3 package for simulating quantum error correction using stabilizer codes.

null 44 Dec 20, 2022
Demodulate and error correct FIS-B and ADS-B signals on 978 MHz.

FIS-B 978 ('fisb-978') is a set of programs that demodulates and error corrects FIS-B (Flight Information System - Broadcast) and ADS-B (Automatic Dep

null 2 Nov 15, 2022
Translation patch for Hololive ERROR

Translation patch for Hololive ERROR How do I install the patch? Grab the Translation.zip file for the latest version from the releases page, and unzi

null 18 Jul 20, 2022
Python package that mirrors the original Nodejs ReplAPI-It.

Python-ReplAPI-It Python package that mirrors the original Nodejs ReplAPI-It. Contributing First fork the repo: $ git clone https://github.com/ReplAPI

The ReplAPI.it Project 10 Jun 5, 2022
pyForgeCert is a Python equivalent of the original ForgeCert written in C#.

pyForgeCert is a Python equivalent of the original ForgeCert written in C#.

Evi1cg 47 Oct 8, 2022
Python script which synchronizes the replica-directoty with the original-one.

directories_synchronizer Python script which synchronizes the replica-directoty with the original-one. Automatically detects all changes when script i

null 0 Feb 13, 2022
A "multiclipboards" script for an efficient way to improve the original clipboards which are only able to save one string at a time

A "multiclipboards" script for an efficient way to improve the original clipboards which are only able to save one string at a time. Works on both Windows and Linux.

null 1 Jan 24, 2022