Skip to main content

Custom messages for errors

Project description

error-explainer

This is a project aimed at tool developers who want to create custom error checks provide better messages with improved location, accuracy and message quality for different errors in Python.

Some checks for syntax errors are provided out of the box.

Currently available checks can be found in error-explainer/messages.py

Installation

To install this package use pip install error-explainer

Usage

Check a Python file for possible errors

from error_explainer.check_runner import run_checks

messages = run_checks("path/to/file")

Messages will be a list of strings containing the generated messages.

Add a new custom check

Custom checks can be added to the list of checks ran while calling run_checks(). To add a new check use @add_check(force: bool) annotation. Force parameter defines if the check is ran only if the code does not compile (False) or always (True)

from error_explainer.check_runner import add_check, add_message

@add_check(False)
def custom_check(filename):
    # code for the check  
    if error_in_file:
        # To add a message to the list of messages returned when calling run_checks() use 
        add_message("code_for_the_message", argument1="foo", argument2="bar")
        # Custom arguments can be used in the message text to make messages more dynamic

Manage messages

Messages used in checks can be:

added

from error_explainer.messages import add_message

# message text can contain arguments in curly brackets these can be later given values using kwargs
add_message("code_for_the_message", "Message text with {dynamic_arguments}")

removed

from error_explainer.messages import remove_message

remove_message("code_for_the_message")

overwritten

from error_explainer.messages import overwrite_message

overwrite_message("code_for_the_message", "Message text with {dynamic_arguments}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for error-explainer, version 0.3
Filename, size File type Python version Upload date Hashes
Filename, size error_explainer-0.3-py3.7.egg (41.1 kB) File type Egg Python version 3.7 Upload date Hashes View
Filename, size error-explainer-0.3.tar.gz (20.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page