error-translator-cli-v2 1.0.6__tar.gz → 1.0.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- error_translator_cli_v2-1.0.8/PKG-INFO +132 -0
- error_translator_cli_v2-1.0.8/README.md +124 -0
- {error_translator_cli_v2-1.0.6 → error_translator_cli_v2-1.0.8}/error_translator/core.py +37 -25
- error_translator_cli_v2-1.0.8/error_translator_cli_v2.egg-info/PKG-INFO +132 -0
- {error_translator_cli_v2-1.0.6 → error_translator_cli_v2-1.0.8}/pyproject.toml +1 -1
- {error_translator_cli_v2-1.0.6 → error_translator_cli_v2-1.0.8}/tests/test_core.py +20 -2
- error_translator_cli_v2-1.0.6/PKG-INFO +0 -78
- error_translator_cli_v2-1.0.6/README.md +0 -70
- error_translator_cli_v2-1.0.6/error_translator_cli_v2.egg-info/PKG-INFO +0 -78
- {error_translator_cli_v2-1.0.6 → error_translator_cli_v2-1.0.8}/error_translator/__init__.py +0 -0
- {error_translator_cli_v2-1.0.6 → error_translator_cli_v2-1.0.8}/error_translator/ast_handlers.py +0 -0
- {error_translator_cli_v2-1.0.6 → error_translator_cli_v2-1.0.8}/error_translator/auto.py +0 -0
- {error_translator_cli_v2-1.0.6 → error_translator_cli_v2-1.0.8}/error_translator/cli.py +0 -0
- {error_translator_cli_v2-1.0.6 → error_translator_cli_v2-1.0.8}/error_translator/server.py +0 -0
- {error_translator_cli_v2-1.0.6 → error_translator_cli_v2-1.0.8}/error_translator_cli_v2.egg-info/SOURCES.txt +0 -0
- {error_translator_cli_v2-1.0.6 → error_translator_cli_v2-1.0.8}/error_translator_cli_v2.egg-info/dependency_links.txt +0 -0
- {error_translator_cli_v2-1.0.6 → error_translator_cli_v2-1.0.8}/error_translator_cli_v2.egg-info/entry_points.txt +0 -0
- {error_translator_cli_v2-1.0.6 → error_translator_cli_v2-1.0.8}/error_translator_cli_v2.egg-info/top_level.txt +0 -0
- {error_translator_cli_v2-1.0.6 → error_translator_cli_v2-1.0.8}/setup.cfg +0 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: error-translator-cli-v2
|
|
3
|
+
Version: 1.0.8
|
|
4
|
+
Summary: A CLI tool that explains Python errors in simple human language.
|
|
5
|
+
Author-email: Gourabananda Datta <gourabanandadatta@zohomail.com>
|
|
6
|
+
Requires-Python: >=3.7
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
9
|
+
# Error Translator CLI
|
|
10
|
+
|
|
11
|
+
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.
|
|
12
|
+
|
|
13
|
+
## Highlights
|
|
14
|
+
|
|
15
|
+
- Runs locally with no model inference or external API calls during normal translation.
|
|
16
|
+
- Supports three entry points: automatic crash interception, CLI execution, and direct traceback translation.
|
|
17
|
+
- Extracts file and line information from standard Python tracebacks when available.
|
|
18
|
+
- Includes optional AST-based insight hooks for a few error families.
|
|
19
|
+
- Provides both machine-readable results and colorized terminal output.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Install the published package with pip:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install error-translator-cli-v2
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
For local development or running the project from source, install the repository dependencies instead:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install -r requirements.txt
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
### 1. Automatic crash interception
|
|
38
|
+
|
|
39
|
+
Import `error_translator.auto` at the top of a script to replace Python's default exception hook with the translated output.
|
|
40
|
+
|
|
41
|
+
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.
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
import error_translator.auto
|
|
45
|
+
|
|
46
|
+
maximum_user_connections = 100
|
|
47
|
+
print(maximum_user_connectons)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Use this when you want the translation to happen automatically without wrapping your code in a custom try/except block.
|
|
51
|
+
|
|
52
|
+
### 2. CLI execution
|
|
53
|
+
|
|
54
|
+
Run a script through the CLI and let the tool translate crashes from `stderr`.
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
explain-error run script.py
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
You can also translate a raw traceback or error string directly:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
explain-error "TypeError: unsupported operand type(s) for +: 'int' and 'str'"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
If you want to pipe a saved traceback into the tool, use the shell syntax for your terminal:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
Get-Content error.log | explain-error
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
cat error.log | explain-error
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 3. Programmatic use
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from error_translator.core import translate_error
|
|
80
|
+
|
|
81
|
+
result = translate_error(traceback_text)
|
|
82
|
+
print(result["explanation"])
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 4. HTTP API
|
|
86
|
+
|
|
87
|
+
Start the FastAPI app with Uvicorn:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
uvicorn error_translator.server:app --reload
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`POST /translate` expects JSON in the form:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"traceback_setting": "Traceback (most recent call last): ..."
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## What the translator returns
|
|
102
|
+
|
|
103
|
+
The translation engine returns a dictionary with these fields when available:
|
|
104
|
+
|
|
105
|
+
- `explanation`
|
|
106
|
+
- `fix`
|
|
107
|
+
- `matched_error`
|
|
108
|
+
- `file`
|
|
109
|
+
- `line`
|
|
110
|
+
- `code`
|
|
111
|
+
- `ast_insight`
|
|
112
|
+
|
|
113
|
+
## Supported errors
|
|
114
|
+
|
|
115
|
+
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.
|
|
116
|
+
|
|
117
|
+
## Project layout
|
|
118
|
+
|
|
119
|
+
- `error_translator/core.py` loads the rule set and performs the translation.
|
|
120
|
+
- `error_translator/cli.py` provides the `explain-error` command.
|
|
121
|
+
- `error_translator/auto.py` installs the automatic exception hook.
|
|
122
|
+
- `error_translator/server.py` exposes the HTTP API.
|
|
123
|
+
- `error_translator/ast_handlers.py` contains contextual suggestion hooks.
|
|
124
|
+
- `error_translator/rules.json` stores the rule database.
|
|
125
|
+
|
|
126
|
+
## Development notes
|
|
127
|
+
|
|
128
|
+
- `builder.py` can generate new rule drafts with Gemini when `GEMINI_API_KEY` is set.
|
|
129
|
+
- `scraper.py` refreshes the scraped exception dataset from the official Python documentation.
|
|
130
|
+
- `tests/test_core.py` contains the current regression coverage for the translation engine.
|
|
131
|
+
|
|
132
|
+
Built by Gourabananda Datta.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# Error Translator CLI
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
## Highlights
|
|
6
|
+
|
|
7
|
+
- Runs locally with no model inference or external API calls during normal translation.
|
|
8
|
+
- Supports three entry points: automatic crash interception, CLI execution, and direct traceback translation.
|
|
9
|
+
- Extracts file and line information from standard Python tracebacks when available.
|
|
10
|
+
- Includes optional AST-based insight hooks for a few error families.
|
|
11
|
+
- Provides both machine-readable results and colorized terminal output.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
Install the published package with pip:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install error-translator-cli-v2
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
For local development or running the project from source, install the repository dependencies instead:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install -r requirements.txt
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### 1. Automatic crash interception
|
|
30
|
+
|
|
31
|
+
Import `error_translator.auto` at the top of a script to replace Python's default exception hook with the translated output.
|
|
32
|
+
|
|
33
|
+
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.
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
import error_translator.auto
|
|
37
|
+
|
|
38
|
+
maximum_user_connections = 100
|
|
39
|
+
print(maximum_user_connectons)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Use this when you want the translation to happen automatically without wrapping your code in a custom try/except block.
|
|
43
|
+
|
|
44
|
+
### 2. CLI execution
|
|
45
|
+
|
|
46
|
+
Run a script through the CLI and let the tool translate crashes from `stderr`.
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
explain-error run script.py
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
You can also translate a raw traceback or error string directly:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
explain-error "TypeError: unsupported operand type(s) for +: 'int' and 'str'"
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
If you want to pipe a saved traceback into the tool, use the shell syntax for your terminal:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
Get-Content error.log | explain-error
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
cat error.log | explain-error
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 3. Programmatic use
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from error_translator.core import translate_error
|
|
72
|
+
|
|
73
|
+
result = translate_error(traceback_text)
|
|
74
|
+
print(result["explanation"])
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 4. HTTP API
|
|
78
|
+
|
|
79
|
+
Start the FastAPI app with Uvicorn:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
uvicorn error_translator.server:app --reload
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`POST /translate` expects JSON in the form:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"traceback_setting": "Traceback (most recent call last): ..."
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## What the translator returns
|
|
94
|
+
|
|
95
|
+
The translation engine returns a dictionary with these fields when available:
|
|
96
|
+
|
|
97
|
+
- `explanation`
|
|
98
|
+
- `fix`
|
|
99
|
+
- `matched_error`
|
|
100
|
+
- `file`
|
|
101
|
+
- `line`
|
|
102
|
+
- `code`
|
|
103
|
+
- `ast_insight`
|
|
104
|
+
|
|
105
|
+
## Supported errors
|
|
106
|
+
|
|
107
|
+
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.
|
|
108
|
+
|
|
109
|
+
## Project layout
|
|
110
|
+
|
|
111
|
+
- `error_translator/core.py` loads the rule set and performs the translation.
|
|
112
|
+
- `error_translator/cli.py` provides the `explain-error` command.
|
|
113
|
+
- `error_translator/auto.py` installs the automatic exception hook.
|
|
114
|
+
- `error_translator/server.py` exposes the HTTP API.
|
|
115
|
+
- `error_translator/ast_handlers.py` contains contextual suggestion hooks.
|
|
116
|
+
- `error_translator/rules.json` stores the rule database.
|
|
117
|
+
|
|
118
|
+
## Development notes
|
|
119
|
+
|
|
120
|
+
- `builder.py` can generate new rule drafts with Gemini when `GEMINI_API_KEY` is set.
|
|
121
|
+
- `scraper.py` refreshes the scraped exception dataset from the official Python documentation.
|
|
122
|
+
- `tests/test_core.py` contains the current regression coverage for the translation engine.
|
|
123
|
+
|
|
124
|
+
Built by Gourabananda Datta.
|
|
@@ -1,50 +1,62 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import os
|
|
3
|
+
import re
|
|
4
|
+
import linecache
|
|
5
|
+
from functools import lru_cache
|
|
3
6
|
from .ast_handlers import AST_REGISTRY
|
|
4
7
|
|
|
8
|
+
|
|
9
|
+
@lru_cache(maxsize=1)
|
|
5
10
|
def load_rules():
|
|
6
|
-
"""
|
|
7
|
-
# Find the absolute path to the json file next to this script
|
|
11
|
+
"""Load the error rules from disk once and cache them."""
|
|
8
12
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
9
|
-
json_path = os.path.join(current_dir,
|
|
10
|
-
|
|
11
|
-
with open(json_path,
|
|
13
|
+
json_path = os.path.join(current_dir, "rules.json")
|
|
14
|
+
|
|
15
|
+
with open(json_path, "r", encoding="utf-8") as file:
|
|
12
16
|
return json.load(file)
|
|
13
17
|
|
|
18
|
+
|
|
19
|
+
@lru_cache(maxsize=1)
|
|
20
|
+
def compiled_rules():
|
|
21
|
+
"""Compile regex patterns once to avoid repeated work per translation."""
|
|
22
|
+
data = load_rules()
|
|
23
|
+
compiled = []
|
|
24
|
+
for rule in data["rules"]:
|
|
25
|
+
compiled.append((re.compile(rule["pattern"]), rule))
|
|
26
|
+
return compiled
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _extract_location(traceback_text: str) -> tuple[str, str]:
|
|
30
|
+
location_match = re.search(r'File\s+[\'"]?(.*?)[\'"]?,\s+line\s+(\d+)', traceback_text)
|
|
31
|
+
if not location_match:
|
|
32
|
+
return "Unknown File", "Unknown Line"
|
|
33
|
+
return location_match.group(1), location_match.group(2)
|
|
34
|
+
|
|
35
|
+
|
|
14
36
|
def translate_error(traceback_text: str) -> dict:
|
|
15
|
-
import re
|
|
16
|
-
import linecache # <-- NEW: Lazy import the linecache module
|
|
17
|
-
|
|
18
37
|
data = load_rules()
|
|
19
|
-
rules =
|
|
38
|
+
rules = compiled_rules()
|
|
20
39
|
default_error = data["default"]
|
|
21
40
|
|
|
22
|
-
lines = [line.strip() for line in traceback_text.strip().split(
|
|
41
|
+
lines = [line.strip() for line in traceback_text.strip().split("\n") if line.strip()]
|
|
23
42
|
if not lines:
|
|
24
43
|
return {"explanation": "No error text provided.", "fix": "Provide a valid Python error."}
|
|
25
|
-
|
|
44
|
+
|
|
26
45
|
actual_error_line = lines[-1]
|
|
27
46
|
|
|
28
|
-
|
|
29
|
-
file_name = location_match.group(1) if location_match else "Unknown File"
|
|
30
|
-
line_number = location_match.group(2) if location_match else "Unknown Line"
|
|
47
|
+
file_name, line_number = _extract_location(traceback_text)
|
|
31
48
|
|
|
32
|
-
# --- NEW CONTEXT ENGINE LOGIC ---
|
|
33
49
|
code_context = ""
|
|
34
50
|
if file_name != "Unknown File" and line_number != "Unknown Line":
|
|
35
51
|
try:
|
|
36
|
-
# linecache safely fetches the exact line of code as a string
|
|
37
52
|
raw_line = linecache.getline(file_name, int(line_number))
|
|
38
53
|
if raw_line:
|
|
39
|
-
code_context = raw_line.strip()
|
|
54
|
+
code_context = raw_line.strip()
|
|
40
55
|
except Exception:
|
|
41
|
-
pass
|
|
42
|
-
# --------------------------------
|
|
56
|
+
pass
|
|
43
57
|
|
|
44
|
-
for rule in rules:
|
|
45
|
-
pattern = re.compile(rule["pattern"])
|
|
58
|
+
for pattern, rule in rules:
|
|
46
59
|
match = pattern.search(actual_error_line)
|
|
47
|
-
|
|
48
60
|
if match:
|
|
49
61
|
extracted_values = list(match.groups())
|
|
50
62
|
fix_text = rule["fix"].format(*extracted_values)
|
|
@@ -61,7 +73,7 @@ def translate_error(traceback_text: str) -> dict:
|
|
|
61
73
|
"matched_error": actual_error_line,
|
|
62
74
|
"file": file_name,
|
|
63
75
|
"line": line_number,
|
|
64
|
-
"code": code_context
|
|
76
|
+
"code": code_context,
|
|
65
77
|
}
|
|
66
78
|
|
|
67
79
|
return {
|
|
@@ -70,5 +82,5 @@ def translate_error(traceback_text: str) -> dict:
|
|
|
70
82
|
"matched_error": actual_error_line,
|
|
71
83
|
"file": file_name,
|
|
72
84
|
"line": line_number,
|
|
73
|
-
"code": code_context
|
|
74
|
-
}
|
|
85
|
+
"code": code_context,
|
|
86
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: error-translator-cli-v2
|
|
3
|
+
Version: 1.0.8
|
|
4
|
+
Summary: A CLI tool that explains Python errors in simple human language.
|
|
5
|
+
Author-email: Gourabananda Datta <gourabanandadatta@zohomail.com>
|
|
6
|
+
Requires-Python: >=3.7
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
9
|
+
# Error Translator CLI
|
|
10
|
+
|
|
11
|
+
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.
|
|
12
|
+
|
|
13
|
+
## Highlights
|
|
14
|
+
|
|
15
|
+
- Runs locally with no model inference or external API calls during normal translation.
|
|
16
|
+
- Supports three entry points: automatic crash interception, CLI execution, and direct traceback translation.
|
|
17
|
+
- Extracts file and line information from standard Python tracebacks when available.
|
|
18
|
+
- Includes optional AST-based insight hooks for a few error families.
|
|
19
|
+
- Provides both machine-readable results and colorized terminal output.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Install the published package with pip:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install error-translator-cli-v2
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
For local development or running the project from source, install the repository dependencies instead:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install -r requirements.txt
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
### 1. Automatic crash interception
|
|
38
|
+
|
|
39
|
+
Import `error_translator.auto` at the top of a script to replace Python's default exception hook with the translated output.
|
|
40
|
+
|
|
41
|
+
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.
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
import error_translator.auto
|
|
45
|
+
|
|
46
|
+
maximum_user_connections = 100
|
|
47
|
+
print(maximum_user_connectons)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Use this when you want the translation to happen automatically without wrapping your code in a custom try/except block.
|
|
51
|
+
|
|
52
|
+
### 2. CLI execution
|
|
53
|
+
|
|
54
|
+
Run a script through the CLI and let the tool translate crashes from `stderr`.
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
explain-error run script.py
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
You can also translate a raw traceback or error string directly:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
explain-error "TypeError: unsupported operand type(s) for +: 'int' and 'str'"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
If you want to pipe a saved traceback into the tool, use the shell syntax for your terminal:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
Get-Content error.log | explain-error
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
cat error.log | explain-error
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 3. Programmatic use
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from error_translator.core import translate_error
|
|
80
|
+
|
|
81
|
+
result = translate_error(traceback_text)
|
|
82
|
+
print(result["explanation"])
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 4. HTTP API
|
|
86
|
+
|
|
87
|
+
Start the FastAPI app with Uvicorn:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
uvicorn error_translator.server:app --reload
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`POST /translate` expects JSON in the form:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"traceback_setting": "Traceback (most recent call last): ..."
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## What the translator returns
|
|
102
|
+
|
|
103
|
+
The translation engine returns a dictionary with these fields when available:
|
|
104
|
+
|
|
105
|
+
- `explanation`
|
|
106
|
+
- `fix`
|
|
107
|
+
- `matched_error`
|
|
108
|
+
- `file`
|
|
109
|
+
- `line`
|
|
110
|
+
- `code`
|
|
111
|
+
- `ast_insight`
|
|
112
|
+
|
|
113
|
+
## Supported errors
|
|
114
|
+
|
|
115
|
+
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.
|
|
116
|
+
|
|
117
|
+
## Project layout
|
|
118
|
+
|
|
119
|
+
- `error_translator/core.py` loads the rule set and performs the translation.
|
|
120
|
+
- `error_translator/cli.py` provides the `explain-error` command.
|
|
121
|
+
- `error_translator/auto.py` installs the automatic exception hook.
|
|
122
|
+
- `error_translator/server.py` exposes the HTTP API.
|
|
123
|
+
- `error_translator/ast_handlers.py` contains contextual suggestion hooks.
|
|
124
|
+
- `error_translator/rules.json` stores the rule database.
|
|
125
|
+
|
|
126
|
+
## Development notes
|
|
127
|
+
|
|
128
|
+
- `builder.py` can generate new rule drafts with Gemini when `GEMINI_API_KEY` is set.
|
|
129
|
+
- `scraper.py` refreshes the scraped exception dataset from the official Python documentation.
|
|
130
|
+
- `tests/test_core.py` contains the current regression coverage for the translation engine.
|
|
131
|
+
|
|
132
|
+
Built by Gourabananda Datta.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import pytest
|
|
2
|
-
from error_translator.core import translate_error
|
|
2
|
+
from error_translator.core import translate_error, load_rules, compiled_rules
|
|
3
3
|
|
|
4
4
|
# --- 1. EDGE CASE TESTS ---
|
|
5
5
|
|
|
@@ -35,6 +35,24 @@ def test_unknown_error_fallback():
|
|
|
35
35
|
assert result["matched_error"] == "Something completely random went wrong here."
|
|
36
36
|
|
|
37
37
|
|
|
38
|
+
def test_empty_input_returns_helpful_message():
|
|
39
|
+
result = translate_error(" \n ")
|
|
40
|
+
assert result["explanation"] == "No error text provided."
|
|
41
|
+
assert result["fix"] == "Provide a valid Python error."
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_rule_loading_is_cached():
|
|
45
|
+
first = load_rules()
|
|
46
|
+
second = load_rules()
|
|
47
|
+
assert first is second
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_compiled_rules_are_cached():
|
|
51
|
+
first = compiled_rules()
|
|
52
|
+
second = compiled_rules()
|
|
53
|
+
assert first is second
|
|
54
|
+
|
|
55
|
+
|
|
38
56
|
# --- 2. THE PARAMETERIZED ENGINE FOR ALL ERRORS ---
|
|
39
57
|
|
|
40
58
|
@pytest.mark.parametrize("mock_traceback, expected_in_explanation", [
|
|
@@ -128,4 +146,4 @@ def test_regex_extraction_for_supported_errors(mock_traceback, expected_in_expla
|
|
|
128
146
|
|
|
129
147
|
# 2. Prove the Context Engine successfully parsed the file location
|
|
130
148
|
assert result["file"] == "script.py"
|
|
131
|
-
assert result["line"] == "5"
|
|
149
|
+
assert result["line"] == "5"
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: error-translator-cli-v2
|
|
3
|
-
Version: 1.0.6
|
|
4
|
-
Summary: A CLI tool that explains Python errors in simple human language.
|
|
5
|
-
Author-email: Gourabananda Datta <gourabanandadatta@zohomail.com>
|
|
6
|
-
Requires-Python: >=3.7
|
|
7
|
-
Description-Content-Type: text/markdown
|
|
8
|
-
|
|
9
|
-
# Error Translator CLI
|
|
10
|
-
|
|
11
|
-
## Overview
|
|
12
|
-
A lightweight, rule-based command-line tool designed to translate confusing Python traceback errors into plain, human-readable English and suggest actionable fixes.
|
|
13
|
-
|
|
14
|
-
## Key Features
|
|
15
|
-
- **No AI or LLMs Required:** Runs entirely locally using fast, regex-based pattern matching.
|
|
16
|
-
- **Beginner Friendly:** Explains the root cause of errors in simple English terminology, making debugging more approachable.
|
|
17
|
-
- **Actionable Guidance:** Provides practical, suggested fixes tailored to your specific code context.
|
|
18
|
-
- **Pinpoint Accuracy:** Extracts and highlights the exact file name and line number where the code encountered an issue.
|
|
19
|
-
- **Improved Readability:** Utilizes well-formatted, color-coded terminal output to make reading errors easier.
|
|
20
|
-
|
|
21
|
-
## Installation
|
|
22
|
-
You can install this tool globally on your machine using pip:
|
|
23
|
-
```bash
|
|
24
|
-
pip install error-translator-cli-v2
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Quick Start Guide
|
|
28
|
-
You can use the Error Translator in three distinct ways, depending on your preferred workflow:
|
|
29
|
-
|
|
30
|
-
### 1. Magic Import (Recommended)
|
|
31
|
-
Simply add this single import statement at the top of your Python script. If your script crashes, the tool will automatically intercept and translate the error.
|
|
32
|
-
|
|
33
|
-
```python
|
|
34
|
-
import error_translator.auto
|
|
35
|
-
|
|
36
|
-
# Your normal code...
|
|
37
|
-
math_is_broken = 10 / 0 # This crash will be automatically intercepted and translated
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### 2. Run Scripts via CLI
|
|
41
|
-
You can execute your Python files directly through the provided CLI tool. It will run your program normally and intercept any crashes if they occur.
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
explain-error run script.py
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### 3. Translate Raw Error Strings
|
|
48
|
-
You can also pass raw error messages directly as a string or pipe them from another command.
|
|
49
|
-
|
|
50
|
-
**Pass directly:**
|
|
51
|
-
```bash
|
|
52
|
-
explain-error "TypeError: unsupported operand type(s) for +: 'int' and 'str'"
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
**Pipe from a file:**
|
|
56
|
-
```bash
|
|
57
|
-
cat error.log | explain-error
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
## Supported Errors
|
|
61
|
-
Currently, the tool can accurately diagnose and explain the following Python errors:
|
|
62
|
-
- NameError
|
|
63
|
-
- TypeError
|
|
64
|
-
- IndexError
|
|
65
|
-
- KeyError
|
|
66
|
-
- ZeroDivisionError
|
|
67
|
-
- ModuleNotFoundError
|
|
68
|
-
- AttributeError
|
|
69
|
-
|
|
70
|
-
*Note: More error definitions are actively being added to the database.*
|
|
71
|
-
|
|
72
|
-
## Cloud API
|
|
73
|
-
This tool includes a built-in FastAPI server so you can integrate the translation engine into your own web apps or VS Code extensions.
|
|
74
|
-
```bash
|
|
75
|
-
uvicorn error_translator.server:app --reload
|
|
76
|
-
```
|
|
77
|
-
---
|
|
78
|
-
Built by Gourabananda Datta.
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# Error Translator CLI
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
A lightweight, rule-based command-line tool designed to translate confusing Python traceback errors into plain, human-readable English and suggest actionable fixes.
|
|
5
|
-
|
|
6
|
-
## Key Features
|
|
7
|
-
- **No AI or LLMs Required:** Runs entirely locally using fast, regex-based pattern matching.
|
|
8
|
-
- **Beginner Friendly:** Explains the root cause of errors in simple English terminology, making debugging more approachable.
|
|
9
|
-
- **Actionable Guidance:** Provides practical, suggested fixes tailored to your specific code context.
|
|
10
|
-
- **Pinpoint Accuracy:** Extracts and highlights the exact file name and line number where the code encountered an issue.
|
|
11
|
-
- **Improved Readability:** Utilizes well-formatted, color-coded terminal output to make reading errors easier.
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
14
|
-
You can install this tool globally on your machine using pip:
|
|
15
|
-
```bash
|
|
16
|
-
pip install error-translator-cli-v2
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Quick Start Guide
|
|
20
|
-
You can use the Error Translator in three distinct ways, depending on your preferred workflow:
|
|
21
|
-
|
|
22
|
-
### 1. Magic Import (Recommended)
|
|
23
|
-
Simply add this single import statement at the top of your Python script. If your script crashes, the tool will automatically intercept and translate the error.
|
|
24
|
-
|
|
25
|
-
```python
|
|
26
|
-
import error_translator.auto
|
|
27
|
-
|
|
28
|
-
# Your normal code...
|
|
29
|
-
math_is_broken = 10 / 0 # This crash will be automatically intercepted and translated
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### 2. Run Scripts via CLI
|
|
33
|
-
You can execute your Python files directly through the provided CLI tool. It will run your program normally and intercept any crashes if they occur.
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
explain-error run script.py
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### 3. Translate Raw Error Strings
|
|
40
|
-
You can also pass raw error messages directly as a string or pipe them from another command.
|
|
41
|
-
|
|
42
|
-
**Pass directly:**
|
|
43
|
-
```bash
|
|
44
|
-
explain-error "TypeError: unsupported operand type(s) for +: 'int' and 'str'"
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
**Pipe from a file:**
|
|
48
|
-
```bash
|
|
49
|
-
cat error.log | explain-error
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## Supported Errors
|
|
53
|
-
Currently, the tool can accurately diagnose and explain the following Python errors:
|
|
54
|
-
- NameError
|
|
55
|
-
- TypeError
|
|
56
|
-
- IndexError
|
|
57
|
-
- KeyError
|
|
58
|
-
- ZeroDivisionError
|
|
59
|
-
- ModuleNotFoundError
|
|
60
|
-
- AttributeError
|
|
61
|
-
|
|
62
|
-
*Note: More error definitions are actively being added to the database.*
|
|
63
|
-
|
|
64
|
-
## Cloud API
|
|
65
|
-
This tool includes a built-in FastAPI server so you can integrate the translation engine into your own web apps or VS Code extensions.
|
|
66
|
-
```bash
|
|
67
|
-
uvicorn error_translator.server:app --reload
|
|
68
|
-
```
|
|
69
|
-
---
|
|
70
|
-
Built by Gourabananda Datta.
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: error-translator-cli-v2
|
|
3
|
-
Version: 1.0.6
|
|
4
|
-
Summary: A CLI tool that explains Python errors in simple human language.
|
|
5
|
-
Author-email: Gourabananda Datta <gourabanandadatta@zohomail.com>
|
|
6
|
-
Requires-Python: >=3.7
|
|
7
|
-
Description-Content-Type: text/markdown
|
|
8
|
-
|
|
9
|
-
# Error Translator CLI
|
|
10
|
-
|
|
11
|
-
## Overview
|
|
12
|
-
A lightweight, rule-based command-line tool designed to translate confusing Python traceback errors into plain, human-readable English and suggest actionable fixes.
|
|
13
|
-
|
|
14
|
-
## Key Features
|
|
15
|
-
- **No AI or LLMs Required:** Runs entirely locally using fast, regex-based pattern matching.
|
|
16
|
-
- **Beginner Friendly:** Explains the root cause of errors in simple English terminology, making debugging more approachable.
|
|
17
|
-
- **Actionable Guidance:** Provides practical, suggested fixes tailored to your specific code context.
|
|
18
|
-
- **Pinpoint Accuracy:** Extracts and highlights the exact file name and line number where the code encountered an issue.
|
|
19
|
-
- **Improved Readability:** Utilizes well-formatted, color-coded terminal output to make reading errors easier.
|
|
20
|
-
|
|
21
|
-
## Installation
|
|
22
|
-
You can install this tool globally on your machine using pip:
|
|
23
|
-
```bash
|
|
24
|
-
pip install error-translator-cli-v2
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Quick Start Guide
|
|
28
|
-
You can use the Error Translator in three distinct ways, depending on your preferred workflow:
|
|
29
|
-
|
|
30
|
-
### 1. Magic Import (Recommended)
|
|
31
|
-
Simply add this single import statement at the top of your Python script. If your script crashes, the tool will automatically intercept and translate the error.
|
|
32
|
-
|
|
33
|
-
```python
|
|
34
|
-
import error_translator.auto
|
|
35
|
-
|
|
36
|
-
# Your normal code...
|
|
37
|
-
math_is_broken = 10 / 0 # This crash will be automatically intercepted and translated
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### 2. Run Scripts via CLI
|
|
41
|
-
You can execute your Python files directly through the provided CLI tool. It will run your program normally and intercept any crashes if they occur.
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
explain-error run script.py
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### 3. Translate Raw Error Strings
|
|
48
|
-
You can also pass raw error messages directly as a string or pipe them from another command.
|
|
49
|
-
|
|
50
|
-
**Pass directly:**
|
|
51
|
-
```bash
|
|
52
|
-
explain-error "TypeError: unsupported operand type(s) for +: 'int' and 'str'"
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
**Pipe from a file:**
|
|
56
|
-
```bash
|
|
57
|
-
cat error.log | explain-error
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
## Supported Errors
|
|
61
|
-
Currently, the tool can accurately diagnose and explain the following Python errors:
|
|
62
|
-
- NameError
|
|
63
|
-
- TypeError
|
|
64
|
-
- IndexError
|
|
65
|
-
- KeyError
|
|
66
|
-
- ZeroDivisionError
|
|
67
|
-
- ModuleNotFoundError
|
|
68
|
-
- AttributeError
|
|
69
|
-
|
|
70
|
-
*Note: More error definitions are actively being added to the database.*
|
|
71
|
-
|
|
72
|
-
## Cloud API
|
|
73
|
-
This tool includes a built-in FastAPI server so you can integrate the translation engine into your own web apps or VS Code extensions.
|
|
74
|
-
```bash
|
|
75
|
-
uvicorn error_translator.server:app --reload
|
|
76
|
-
```
|
|
77
|
-
---
|
|
78
|
-
Built by Gourabananda Datta.
|
{error_translator_cli_v2-1.0.6 → error_translator_cli_v2-1.0.8}/error_translator/__init__.py
RENAMED
|
File without changes
|
{error_translator_cli_v2-1.0.6 → error_translator_cli_v2-1.0.8}/error_translator/ast_handlers.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|