Giter Club home page Giter Club logo

error-explainer's Introduction

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}")

error-explainer's People

Contributors

dependabot[bot] avatar kaareloide avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.