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, 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 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.

Source Distribution

error-explainer-0.6.tar.gz (22.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

error_explainer-0.6-py3.6.egg (44.1 kB view details)

Uploaded Egg

File details

Details for the file error-explainer-0.6.tar.gz.

File metadata

  • Download URL: error-explainer-0.6.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for error-explainer-0.6.tar.gz
Algorithm Hash digest
SHA256 5e0b20fd87bc2dc2a1a10c0aaebd8e2028e44709b81071ece71ce878321141d4
MD5 74acf12d65781ec1b24cb394c6cb2a35
BLAKE2b-256 fa7fc49793714ce5045a95fb308872be19861edd659f137e531b749df6e0ddbf

See more details on using hashes here.

File details

Details for the file error_explainer-0.6-py3.6.egg.

File metadata

  • Download URL: error_explainer-0.6-py3.6.egg
  • Upload date:
  • Size: 44.1 kB
  • Tags: Egg
  • Uploaded using 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

File hashes

Hashes for error_explainer-0.6-py3.6.egg
Algorithm Hash digest
SHA256 9f1dcb6d3ac45bbcec3ff8140b868b57ac8c6cbfc5008ce1b86af8d14dd02c84
MD5 e43ee90429d7741c588ee7496a58a7a0
BLAKE2b-256 01f2d763e23b93adaf9bdf67486cd02a97040a3196de9f0bcc80e0bb6f5c072c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page