Skip to main content

A CLI tool that explains Python errors in simple human language.

Project description

Error Translator CLI

Error Translator CLI turns Python tracebacks into clear, actionable explanations. It is a local, rule-based tool that reads the final error line, matches it against a curated regex rule set, and returns a structured translation with the original file, line number, code context, and a suggested fix.

Highlights

  • Runs locally with no model inference or external API calls during normal translation.
  • Supports three entry points: automatic crash interception, CLI execution, and direct traceback translation.
  • Extracts file and line information from standard Python tracebacks when available.
  • Includes optional AST-based insight hooks for a few error families.
  • Provides both machine-readable results and colorized terminal output.

Installation

Install the published package with pip:

pip install error-translator-cli-v2

For local development or running the project from source, install the repository dependencies instead:

pip install -r requirements.txt

Usage

1. Automatic crash interception

Import error_translator.auto at the top of a script to replace Python's default exception hook with the translated output.

This is the project's magic import: once imported, any unhandled exception in that process is intercepted and formatted by the translator before Python prints the default traceback.

import error_translator.auto

maximum_user_connections = 100
print(maximum_user_connectons)

Use this when you want the translation to happen automatically without wrapping your code in a custom try/except block.

2. CLI execution

Run a script through the CLI and let the tool translate crashes from stderr.

explain-error run script.py

You can also translate a raw traceback or error string directly:

explain-error "TypeError: unsupported operand type(s) for +: 'int' and 'str'"

If you want to pipe a saved traceback into the tool, use the shell syntax for your terminal:

Get-Content error.log | explain-error
cat error.log | explain-error

3. Programmatic use

from error_translator.core import translate_error

result = translate_error(traceback_text)
print(result["explanation"])

4. HTTP API

Start the FastAPI app with Uvicorn:

uvicorn error_translator.server:app --reload

POST /translate expects JSON in the form:

{
	"traceback_setting": "Traceback (most recent call last): ..."
}

What the translator returns

The translation engine returns a dictionary with these fields when available:

  • explanation
  • fix
  • matched_error
  • file
  • line
  • code
  • ast_insight

Supported errors

The bundled rule set covers many common Python runtime, syntax, indentation, import, OS, encoding, and networking errors. The full list lives in error_translator/rules.json and can be expanded over time without changing the runtime engine.

Project layout

  • error_translator/core.py loads the rule set and performs the translation.
  • error_translator/cli.py provides the explain-error command.
  • error_translator/auto.py installs the automatic exception hook.
  • error_translator/server.py exposes the HTTP API.
  • error_translator/ast_handlers.py contains contextual suggestion hooks.
  • error_translator/rules.json stores the rule database.

Development notes

  • builder.py can generate new rule drafts with Gemini when GEMINI_API_KEY is set.
  • scraper.py refreshes the scraped exception dataset from the official Python documentation.
  • tests/test_core.py contains the current regression coverage for the translation engine.

Built by Gourabananda Datta.

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_translator_cli_v2-1.0.8.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

error_translator_cli_v2-1.0.8-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file error_translator_cli_v2-1.0.8.tar.gz.

File metadata

  • Download URL: error_translator_cli_v2-1.0.8.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for error_translator_cli_v2-1.0.8.tar.gz
Algorithm Hash digest
SHA256 8ccbc0a439b48a02eceab106d67dbdc3acb69bf5bb5e8a67125f65babd36d7f6
MD5 55285fed0db5538678c56ed219e5bb7e
BLAKE2b-256 9c233c375c2b0b29f4ff95f062ab321d3eadbd447e5e25942c04d6663ea4d464

See more details on using hashes here.

File details

Details for the file error_translator_cli_v2-1.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for error_translator_cli_v2-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 e044482954a97397ec3c9c9500c6980a081e77a5429f1f2737e1fb9392390009
MD5 bfd81d311b71c8ea51bf824efc648088
BLAKE2b-256 fcad0e0b97585e394526f2b828e7ab686cfc608d0863b06097b2f487c952f3f3

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