Skip to main content

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, level=99) annotation. Force parameter defines if the check is ran only if the code does not compile (False) or always (True) Checks are also run in multiple levels from 0 to 99. Current layers are the following:

  • 0 - docstring errors, quote errors
  • 1 - miss match bracket errors, missing bracket errors, python 2 style print usage error
  • 2 - invalid function definition errors
  • 3 - missing colon errors, invalid assignment errors
  • 99 - indentation errors, coma used instead of a period in an assignment error
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 create_message

# message text can contain arguments in curly brackets these can be later given values using kwargs
create_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}")

Release files for error-explainer 0.14

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

Source distribution (sdist)

Source distribution for error-explainer 0.14
File Size Uploaded
error-explainer-0.14.tar.gz 23.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for error-explainer 0.14
File Interpreter ABI Platform
error_explainer-0.14-py3.6.egg Legacy Egg format - - Details

Total release size: 67.1 kB

Release files / error-explainer-0.14.tar.gz

Download URL error-explainer-0.14.tar.gz
Size 23.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8e256c7ecb245ad20d310e7e6552c982d23346525bcecf9af9a48c7f7b236b23
BLAKE2b-256 checksum
How to use checksums
0c48e2643a95366038dd9a9c9fec78c940c80d8e50e9e0344068f1df71750a6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.9

Release files / error_explainer-0.14-py3.6.egg

Download URL error_explainer-0.14-py3.6.egg
Size 44.0 kB
Tags Egg
SHA-256 checksum
How to use checksums
54ed9cf9afbcdc4a72f08421e33d5d783eaedf341fe00bb49650967672e2e607
BLAKE2b-256 checksum
How to use checksums
7ccea50f3f36930e9e2c5265ca63321023b31446fc23cf29801d8d58e4ae1cf5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.9

Release history Release notifications | RSS feed

This release

0.14 This release

2 release files

0.13

2 release files

0.12

2 release files

0.11

2 release files

0.10

2 release files

0.9

2 release files

0.8

2 release files

0.7

2 release files

0.6

2 release files

0.5

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

0.1.9

2 release files

0.1

2 release files

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