error-translator-cli-v2 1.0.7__tar.gz → 1.0.9__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.
Files changed (19) hide show
  1. error_translator_cli_v2-1.0.9/PKG-INFO +148 -0
  2. error_translator_cli_v2-1.0.9/README.md +140 -0
  3. {error_translator_cli_v2-1.0.7 → error_translator_cli_v2-1.0.9}/error_translator/core.py +37 -25
  4. error_translator_cli_v2-1.0.9/error_translator_cli_v2.egg-info/PKG-INFO +148 -0
  5. {error_translator_cli_v2-1.0.7 → error_translator_cli_v2-1.0.9}/pyproject.toml +1 -1
  6. {error_translator_cli_v2-1.0.7 → error_translator_cli_v2-1.0.9}/tests/test_core.py +20 -2
  7. error_translator_cli_v2-1.0.7/PKG-INFO +0 -132
  8. error_translator_cli_v2-1.0.7/README.md +0 -124
  9. error_translator_cli_v2-1.0.7/error_translator_cli_v2.egg-info/PKG-INFO +0 -132
  10. {error_translator_cli_v2-1.0.7 → error_translator_cli_v2-1.0.9}/error_translator/__init__.py +0 -0
  11. {error_translator_cli_v2-1.0.7 → error_translator_cli_v2-1.0.9}/error_translator/ast_handlers.py +0 -0
  12. {error_translator_cli_v2-1.0.7 → error_translator_cli_v2-1.0.9}/error_translator/auto.py +0 -0
  13. {error_translator_cli_v2-1.0.7 → error_translator_cli_v2-1.0.9}/error_translator/cli.py +0 -0
  14. {error_translator_cli_v2-1.0.7 → error_translator_cli_v2-1.0.9}/error_translator/server.py +0 -0
  15. {error_translator_cli_v2-1.0.7 → error_translator_cli_v2-1.0.9}/error_translator_cli_v2.egg-info/SOURCES.txt +0 -0
  16. {error_translator_cli_v2-1.0.7 → error_translator_cli_v2-1.0.9}/error_translator_cli_v2.egg-info/dependency_links.txt +0 -0
  17. {error_translator_cli_v2-1.0.7 → error_translator_cli_v2-1.0.9}/error_translator_cli_v2.egg-info/entry_points.txt +0 -0
  18. {error_translator_cli_v2-1.0.7 → error_translator_cli_v2-1.0.9}/error_translator_cli_v2.egg-info/top_level.txt +0 -0
  19. {error_translator_cli_v2-1.0.7 → error_translator_cli_v2-1.0.9}/setup.cfg +0 -0
@@ -0,0 +1,148 @@
1
+ Metadata-Version: 2.4
2
+ Name: error-translator-cli-v2
3
+ Version: 1.0.9
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
10
+
11
+ Error Translator is a Python toolkit that converts raw tracebacks into clear, actionable guidance. The project is designed for local use, deterministic output, and easy extension by contributors.
12
+
13
+ It can be used as:
14
+
15
+ - A CLI (`explain-error`) for direct translation and script execution.
16
+ - An import hook (`error_translator.auto`) for automatic translation of unhandled exceptions.
17
+ - A small FastAPI service (`error_translator.server`) for integrations.
18
+
19
+ ## Why this project exists
20
+
21
+ Python's default tracebacks are precise but can be difficult for beginners and occasional Python users to act on quickly. Error Translator narrows that gap by matching final traceback lines against a curated set of regex rules and returning:
22
+
23
+ - A plain-language explanation.
24
+ - A concrete suggested fix.
25
+ - Location/context metadata when available (`file`, `line`, `code`).
26
+ - Optional AST-based hints for selected error families.
27
+
28
+ ## Key capabilities
29
+
30
+ - **Local and deterministic**: no external API is required for normal translation.
31
+ - **Structured output**: returns a predictable dictionary for CLI, library, and API consumers.
32
+ - **Multiple entry points**: CLI, import hook, and HTTP API share the same core engine.
33
+ - **Contributor-friendly rule model**: behavior is primarily driven by `error_translator/rules.json`.
34
+
35
+ ## Installation
36
+
37
+ ### Install from package
38
+
39
+ ```bash
40
+ pip install error-translator-cli-v2
41
+ ```
42
+
43
+ ### Install for local development
44
+
45
+ ```bash
46
+ pip install -r requirements.txt
47
+ ```
48
+
49
+ ## Usage
50
+
51
+ ### 1) Automatic crash interception
52
+
53
+ ```python
54
+ import error_translator.auto
55
+
56
+ maximum_user_connections = 100
57
+ print(maximum_user_connectons)
58
+ ```
59
+
60
+ Importing `error_translator.auto` installs a custom `sys.excepthook`, so unhandled exceptions are translated automatically in that process.
61
+
62
+ ### 2) CLI mode
63
+
64
+ Run a script and translate any failure from `stderr`:
65
+
66
+ ```bash
67
+ explain-error run script.py
68
+ ```
69
+
70
+ Translate a single raw error string:
71
+
72
+ ```bash
73
+ explain-error "TypeError: unsupported operand type(s) for +: 'int' and 'str'"
74
+ ```
75
+
76
+ Pipe traceback text from a file:
77
+
78
+ ```bash
79
+ cat error.log | explain-error
80
+ ```
81
+
82
+ PowerShell:
83
+
84
+ ```bash
85
+ Get-Content error.log | explain-error
86
+ ```
87
+
88
+ ### 3) Programmatic usage
89
+
90
+ ```python
91
+ from error_translator.core import translate_error
92
+
93
+ result = translate_error(traceback_text)
94
+ print(result["explanation"])
95
+ ```
96
+
97
+ ### 4) HTTP API
98
+
99
+ Start the API:
100
+
101
+ ```bash
102
+ uvicorn error_translator.server:app --reload
103
+ ```
104
+
105
+ `POST /translate` expects:
106
+
107
+ ```json
108
+ {
109
+ "traceback_setting": "Traceback (most recent call last): ..."
110
+ }
111
+ ```
112
+
113
+ ## Response contract
114
+
115
+ `translate_error()` returns a dictionary with these fields when available:
116
+
117
+ - `explanation`
118
+ - `fix`
119
+ - `matched_error`
120
+ - `file`
121
+ - `line`
122
+ - `code`
123
+ - `ast_insight`
124
+
125
+ ## Repository structure
126
+
127
+ - `error_translator/core.py`: translation pipeline and rule matching.
128
+ - `error_translator/cli.py`: terminal interface (`explain-error`).
129
+ - `error_translator/auto.py`: automatic exception-hook integration.
130
+ - `error_translator/server.py`: FastAPI surface.
131
+ - `error_translator/ast_handlers.py`: optional contextual heuristics.
132
+ - `error_translator/rules.json`: primary rule database.
133
+ - `tests/test_core.py`: regression tests for translation behavior.
134
+
135
+ ## Contributing
136
+
137
+ We welcome contributions of all sizes. If you are new to the project:
138
+
139
+ 1. Start with one narrowly scoped improvement.
140
+ 2. Add or update tests for behavior changes.
141
+ 3. Run `pytest` before submitting.
142
+ 4. Keep user-facing docs aligned with implementation.
143
+
144
+ See `docs/CONTRIBUTING.md` for full contributor workflow and review standards.
145
+
146
+ ---
147
+
148
+ Maintained by Gourabananda Datta and contributors.
@@ -0,0 +1,140 @@
1
+ # Error Translator
2
+
3
+ Error Translator is a Python toolkit that converts raw tracebacks into clear, actionable guidance. The project is designed for local use, deterministic output, and easy extension by contributors.
4
+
5
+ It can be used as:
6
+
7
+ - A CLI (`explain-error`) for direct translation and script execution.
8
+ - An import hook (`error_translator.auto`) for automatic translation of unhandled exceptions.
9
+ - A small FastAPI service (`error_translator.server`) for integrations.
10
+
11
+ ## Why this project exists
12
+
13
+ Python's default tracebacks are precise but can be difficult for beginners and occasional Python users to act on quickly. Error Translator narrows that gap by matching final traceback lines against a curated set of regex rules and returning:
14
+
15
+ - A plain-language explanation.
16
+ - A concrete suggested fix.
17
+ - Location/context metadata when available (`file`, `line`, `code`).
18
+ - Optional AST-based hints for selected error families.
19
+
20
+ ## Key capabilities
21
+
22
+ - **Local and deterministic**: no external API is required for normal translation.
23
+ - **Structured output**: returns a predictable dictionary for CLI, library, and API consumers.
24
+ - **Multiple entry points**: CLI, import hook, and HTTP API share the same core engine.
25
+ - **Contributor-friendly rule model**: behavior is primarily driven by `error_translator/rules.json`.
26
+
27
+ ## Installation
28
+
29
+ ### Install from package
30
+
31
+ ```bash
32
+ pip install error-translator-cli-v2
33
+ ```
34
+
35
+ ### Install for local development
36
+
37
+ ```bash
38
+ pip install -r requirements.txt
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ ### 1) Automatic crash interception
44
+
45
+ ```python
46
+ import error_translator.auto
47
+
48
+ maximum_user_connections = 100
49
+ print(maximum_user_connectons)
50
+ ```
51
+
52
+ Importing `error_translator.auto` installs a custom `sys.excepthook`, so unhandled exceptions are translated automatically in that process.
53
+
54
+ ### 2) CLI mode
55
+
56
+ Run a script and translate any failure from `stderr`:
57
+
58
+ ```bash
59
+ explain-error run script.py
60
+ ```
61
+
62
+ Translate a single raw error string:
63
+
64
+ ```bash
65
+ explain-error "TypeError: unsupported operand type(s) for +: 'int' and 'str'"
66
+ ```
67
+
68
+ Pipe traceback text from a file:
69
+
70
+ ```bash
71
+ cat error.log | explain-error
72
+ ```
73
+
74
+ PowerShell:
75
+
76
+ ```bash
77
+ Get-Content error.log | explain-error
78
+ ```
79
+
80
+ ### 3) Programmatic usage
81
+
82
+ ```python
83
+ from error_translator.core import translate_error
84
+
85
+ result = translate_error(traceback_text)
86
+ print(result["explanation"])
87
+ ```
88
+
89
+ ### 4) HTTP API
90
+
91
+ Start the API:
92
+
93
+ ```bash
94
+ uvicorn error_translator.server:app --reload
95
+ ```
96
+
97
+ `POST /translate` expects:
98
+
99
+ ```json
100
+ {
101
+ "traceback_setting": "Traceback (most recent call last): ..."
102
+ }
103
+ ```
104
+
105
+ ## Response contract
106
+
107
+ `translate_error()` returns a dictionary with these fields when available:
108
+
109
+ - `explanation`
110
+ - `fix`
111
+ - `matched_error`
112
+ - `file`
113
+ - `line`
114
+ - `code`
115
+ - `ast_insight`
116
+
117
+ ## Repository structure
118
+
119
+ - `error_translator/core.py`: translation pipeline and rule matching.
120
+ - `error_translator/cli.py`: terminal interface (`explain-error`).
121
+ - `error_translator/auto.py`: automatic exception-hook integration.
122
+ - `error_translator/server.py`: FastAPI surface.
123
+ - `error_translator/ast_handlers.py`: optional contextual heuristics.
124
+ - `error_translator/rules.json`: primary rule database.
125
+ - `tests/test_core.py`: regression tests for translation behavior.
126
+
127
+ ## Contributing
128
+
129
+ We welcome contributions of all sizes. If you are new to the project:
130
+
131
+ 1. Start with one narrowly scoped improvement.
132
+ 2. Add or update tests for behavior changes.
133
+ 3. Run `pytest` before submitting.
134
+ 4. Keep user-facing docs aligned with implementation.
135
+
136
+ See `docs/CONTRIBUTING.md` for full contributor workflow and review standards.
137
+
138
+ ---
139
+
140
+ Maintained by Gourabananda Datta and contributors.
@@ -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
- """Loads the error rules from the JSON file."""
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, 'rules.json')
10
-
11
- with open(json_path, 'r') as file:
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 = data["rules"]
38
+ rules = compiled_rules()
20
39
  default_error = data["default"]
21
40
 
22
- lines = [line.strip() for line in traceback_text.strip().split('\n') if line.strip()]
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
- location_match = re.search(r'File\s+[\'"]?(.*?)[\'"]?,\s+line\s+(\d+)', traceback_text)
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() # Remove extra spaces/newlines
54
+ code_context = raw_line.strip()
40
55
  except Exception:
41
- pass # If the file can't be read for any reason, fail silently
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,148 @@
1
+ Metadata-Version: 2.4
2
+ Name: error-translator-cli-v2
3
+ Version: 1.0.9
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
10
+
11
+ Error Translator is a Python toolkit that converts raw tracebacks into clear, actionable guidance. The project is designed for local use, deterministic output, and easy extension by contributors.
12
+
13
+ It can be used as:
14
+
15
+ - A CLI (`explain-error`) for direct translation and script execution.
16
+ - An import hook (`error_translator.auto`) for automatic translation of unhandled exceptions.
17
+ - A small FastAPI service (`error_translator.server`) for integrations.
18
+
19
+ ## Why this project exists
20
+
21
+ Python's default tracebacks are precise but can be difficult for beginners and occasional Python users to act on quickly. Error Translator narrows that gap by matching final traceback lines against a curated set of regex rules and returning:
22
+
23
+ - A plain-language explanation.
24
+ - A concrete suggested fix.
25
+ - Location/context metadata when available (`file`, `line`, `code`).
26
+ - Optional AST-based hints for selected error families.
27
+
28
+ ## Key capabilities
29
+
30
+ - **Local and deterministic**: no external API is required for normal translation.
31
+ - **Structured output**: returns a predictable dictionary for CLI, library, and API consumers.
32
+ - **Multiple entry points**: CLI, import hook, and HTTP API share the same core engine.
33
+ - **Contributor-friendly rule model**: behavior is primarily driven by `error_translator/rules.json`.
34
+
35
+ ## Installation
36
+
37
+ ### Install from package
38
+
39
+ ```bash
40
+ pip install error-translator-cli-v2
41
+ ```
42
+
43
+ ### Install for local development
44
+
45
+ ```bash
46
+ pip install -r requirements.txt
47
+ ```
48
+
49
+ ## Usage
50
+
51
+ ### 1) Automatic crash interception
52
+
53
+ ```python
54
+ import error_translator.auto
55
+
56
+ maximum_user_connections = 100
57
+ print(maximum_user_connectons)
58
+ ```
59
+
60
+ Importing `error_translator.auto` installs a custom `sys.excepthook`, so unhandled exceptions are translated automatically in that process.
61
+
62
+ ### 2) CLI mode
63
+
64
+ Run a script and translate any failure from `stderr`:
65
+
66
+ ```bash
67
+ explain-error run script.py
68
+ ```
69
+
70
+ Translate a single raw error string:
71
+
72
+ ```bash
73
+ explain-error "TypeError: unsupported operand type(s) for +: 'int' and 'str'"
74
+ ```
75
+
76
+ Pipe traceback text from a file:
77
+
78
+ ```bash
79
+ cat error.log | explain-error
80
+ ```
81
+
82
+ PowerShell:
83
+
84
+ ```bash
85
+ Get-Content error.log | explain-error
86
+ ```
87
+
88
+ ### 3) Programmatic usage
89
+
90
+ ```python
91
+ from error_translator.core import translate_error
92
+
93
+ result = translate_error(traceback_text)
94
+ print(result["explanation"])
95
+ ```
96
+
97
+ ### 4) HTTP API
98
+
99
+ Start the API:
100
+
101
+ ```bash
102
+ uvicorn error_translator.server:app --reload
103
+ ```
104
+
105
+ `POST /translate` expects:
106
+
107
+ ```json
108
+ {
109
+ "traceback_setting": "Traceback (most recent call last): ..."
110
+ }
111
+ ```
112
+
113
+ ## Response contract
114
+
115
+ `translate_error()` returns a dictionary with these fields when available:
116
+
117
+ - `explanation`
118
+ - `fix`
119
+ - `matched_error`
120
+ - `file`
121
+ - `line`
122
+ - `code`
123
+ - `ast_insight`
124
+
125
+ ## Repository structure
126
+
127
+ - `error_translator/core.py`: translation pipeline and rule matching.
128
+ - `error_translator/cli.py`: terminal interface (`explain-error`).
129
+ - `error_translator/auto.py`: automatic exception-hook integration.
130
+ - `error_translator/server.py`: FastAPI surface.
131
+ - `error_translator/ast_handlers.py`: optional contextual heuristics.
132
+ - `error_translator/rules.json`: primary rule database.
133
+ - `tests/test_core.py`: regression tests for translation behavior.
134
+
135
+ ## Contributing
136
+
137
+ We welcome contributions of all sizes. If you are new to the project:
138
+
139
+ 1. Start with one narrowly scoped improvement.
140
+ 2. Add or update tests for behavior changes.
141
+ 3. Run `pytest` before submitting.
142
+ 4. Keep user-facing docs aligned with implementation.
143
+
144
+ See `docs/CONTRIBUTING.md` for full contributor workflow and review standards.
145
+
146
+ ---
147
+
148
+ Maintained by Gourabananda Datta and contributors.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "error-translator-cli-v2"
7
- version = "1.0.7"
7
+ version = "1.0.9"
8
8
  description = "A CLI tool that explains Python errors in simple human language."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.7"
@@ -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,132 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: error-translator-cli-v2
3
- Version: 1.0.7
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,124 +0,0 @@
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,132 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: error-translator-cli-v2
3
- Version: 1.0.7
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.