error-translator-cli-v2 1.1.2__tar.gz → 1.1.4__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.1.4/LICENSE +21 -0
- error_translator_cli_v2-1.1.4/PKG-INFO +178 -0
- error_translator_cli_v2-1.1.4/README.md +114 -0
- {error_translator_cli_v2-1.1.2 → error_translator_cli_v2-1.1.4}/error_translator/cli.py +80 -8
- error_translator_cli_v2-1.1.4/error_translator/rules.json +283 -0
- error_translator_cli_v2-1.1.4/error_translator/server.py +47 -0
- error_translator_cli_v2-1.1.4/error_translator/static/index.html +78 -0
- error_translator_cli_v2-1.1.4/error_translator/static/style.css +93 -0
- error_translator_cli_v2-1.1.4/error_translator_cli_v2.egg-info/PKG-INFO +178 -0
- {error_translator_cli_v2-1.1.2 → error_translator_cli_v2-1.1.4}/error_translator_cli_v2.egg-info/SOURCES.txt +5 -0
- error_translator_cli_v2-1.1.4/error_translator_cli_v2.egg-info/requires.txt +15 -0
- error_translator_cli_v2-1.1.4/pyproject.toml +52 -0
- error_translator_cli_v2-1.1.2/PKG-INFO +0 -237
- error_translator_cli_v2-1.1.2/README.md +0 -226
- error_translator_cli_v2-1.1.2/error_translator/server.py +0 -25
- error_translator_cli_v2-1.1.2/error_translator_cli_v2.egg-info/PKG-INFO +0 -237
- error_translator_cli_v2-1.1.2/pyproject.toml +0 -23
- {error_translator_cli_v2-1.1.2 → error_translator_cli_v2-1.1.4}/error_translator/__init__.py +0 -0
- {error_translator_cli_v2-1.1.2 → error_translator_cli_v2-1.1.4}/error_translator/ast_handlers.py +0 -0
- {error_translator_cli_v2-1.1.2 → error_translator_cli_v2-1.1.4}/error_translator/auto.py +0 -0
- {error_translator_cli_v2-1.1.2 → error_translator_cli_v2-1.1.4}/error_translator/core.py +0 -0
- {error_translator_cli_v2-1.1.2 → error_translator_cli_v2-1.1.4}/error_translator_cli_v2.egg-info/dependency_links.txt +0 -0
- {error_translator_cli_v2-1.1.2 → error_translator_cli_v2-1.1.4}/error_translator_cli_v2.egg-info/entry_points.txt +0 -0
- {error_translator_cli_v2-1.1.2 → error_translator_cli_v2-1.1.4}/error_translator_cli_v2.egg-info/top_level.txt +0 -0
- {error_translator_cli_v2-1.1.2 → error_translator_cli_v2-1.1.4}/setup.cfg +0 -0
- {error_translator_cli_v2-1.1.2 → error_translator_cli_v2-1.1.4}/tests/test_core.py +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gourabananda Datta
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: error-translator-cli-v2
|
|
3
|
+
Version: 1.1.4
|
|
4
|
+
Summary: A CLI tool that explains Python errors in simple human language.
|
|
5
|
+
Author-email: Gourabananda Datta <gourabanandadatta@zohomail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Gourabananda Datta
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/gourabanandad/error-translator
|
|
29
|
+
Project-URL: Source, https://github.com/gourabanandad/error-translator
|
|
30
|
+
Project-URL: Documentation, https://github.com/gourabanandad/error-translator/tree/master/docs
|
|
31
|
+
Project-URL: Issues, https://github.com/gourabanandad/error-translator/issues
|
|
32
|
+
Project-URL: Changelog, https://github.com/gourabanandad/error-translator/releases
|
|
33
|
+
Project-URL: Contributors, https://github.com/gourabanandad/error-translator/graphs/contributors
|
|
34
|
+
Keywords: python,traceback,cli,debugging,error handling,developer tools
|
|
35
|
+
Classifier: Development Status :: 4 - Beta
|
|
36
|
+
Classifier: Environment :: Console
|
|
37
|
+
Classifier: Intended Audience :: Developers
|
|
38
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
39
|
+
Classifier: Operating System :: OS Independent
|
|
40
|
+
Classifier: Programming Language :: Python :: 3
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
43
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
44
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
45
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
46
|
+
Classifier: Topic :: Software Development :: Debuggers
|
|
47
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
48
|
+
Requires-Python: >=3.9
|
|
49
|
+
Description-Content-Type: text/markdown
|
|
50
|
+
License-File: LICENSE
|
|
51
|
+
Provides-Extra: server
|
|
52
|
+
Requires-Dist: fastapi>=0.110; extra == "server"
|
|
53
|
+
Requires-Dist: pydantic>=2.6; extra == "server"
|
|
54
|
+
Requires-Dist: uvicorn>=0.29; extra == "server"
|
|
55
|
+
Provides-Extra: docs
|
|
56
|
+
Requires-Dist: mkdocs>=1.6; extra == "docs"
|
|
57
|
+
Requires-Dist: mkdocs-material>=9.7; extra == "docs"
|
|
58
|
+
Requires-Dist: pymdown-extensions>=10.0; extra == "docs"
|
|
59
|
+
Provides-Extra: dev
|
|
60
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
61
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
62
|
+
Requires-Dist: twine>=5.0; extra == "dev"
|
|
63
|
+
Dynamic: license-file
|
|
64
|
+
|
|
65
|
+
# Error Translator
|
|
66
|
+
|
|
67
|
+
<div align="left">
|
|
68
|
+
<a href="https://pypi.org/project/error-translator-cli-v2/"><img alt="PyPI Version" src="https://img.shields.io/pypi/v/error-translator-cli-v2.svg"></a>
|
|
69
|
+
<img alt="Python 3.9+" src="https://img.shields.io/badge/python-3.9%2B-blue.svg">
|
|
70
|
+
<a href="https://github.com/gourabanandad/error-translator-cli-v2/stargazers"><img alt="GitHub Stars" src="https://img.shields.io/github/stars/gourabanandad/error-translator-cli-v2?style=social"></a>
|
|
71
|
+
<a href="https://pypi.org/project/error-translator-cli-v2/"><img alt="PyPI Downloads" src="https://img.shields.io/pypi/dm/error-translator-cli-v2"></a>
|
|
72
|
+
<a href="https://github.com/gourabanandad/error-translator-cli-v2"><img alt="License" src="https://img.shields.io/github/license/gourabanandad/error-translator-cli-v2.svg"></a>
|
|
73
|
+
<a href="https://github.com/gourabanandad/error-translator-cli-v2/actions/workflows/ci.yml"><img alt="Build Status" src="https://img.shields.io/github/actions/workflow/status/gourabanandad/error-translator-cli-v2/ci.yml?branch=master&label=build"></a>
|
|
74
|
+
</div>
|
|
75
|
+
|
|
76
|
+
<br>
|
|
77
|
+
|
|
78
|
+
**Error Translator** is a powerful offline engine designed to parse raw Python tracebacks and translate them into crystal-clear explanations with immediately actionable fixes. Built with local-first development workflows in mind, it supports direct CLI usage, an automatic import hook, a programmatic Python API, and a FastAPI integration.
|
|
79
|
+
|
|
80
|
+
If this project saves you debugging time, please consider starring it on GitHub: https://github.com/gourabanandad/error-translator-cli-v2
|
|
81
|
+
|
|
82
|
+
## Why Developers Like It
|
|
83
|
+
|
|
84
|
+
* **Fast Feedback Loop**: Turn stack traces into direct next actions in seconds.
|
|
85
|
+
* **Works Offline**: No telemetry dependency for core translation behavior.
|
|
86
|
+
* **Beginner-Friendly Output**: Explanations are clear enough for learners, practical enough for teams.
|
|
87
|
+
* **Multiple Entry Points**: CLI, import hook, Python API, and FastAPI all share one deterministic engine.
|
|
88
|
+
|
|
89
|
+
## Key Features
|
|
90
|
+
|
|
91
|
+
* **CLI-First Architecture**: Seamlessly process scripts, direct error strings, or piped logs via the `explain-error` command.
|
|
92
|
+
* **Automatic Integration Mode**: Inject the module via `import error_translator.auto` to automatically override `sys.excepthook` for graceful, translated crash reporting.
|
|
93
|
+
* **Extensible API Surfaces**: Integrate natively within Python or expose the core engine over HTTP via the included FastAPI server.
|
|
94
|
+
* **Deterministic Rules Engine**: High-performance, regex-based matching powered by `rules.json` guarantees offline and privacy-first translations.
|
|
95
|
+
* **Optional AST Insight Hooks**: Registered handlers can append targeted hints (`ast_insight`) for selected error types.
|
|
96
|
+
|
|
97
|
+
## Installation
|
|
98
|
+
|
|
99
|
+
Python requirement: **3.9 or newer**.
|
|
100
|
+
|
|
101
|
+
Install the latest stable release directly from PyPI:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
pip install error-translator-cli-v2
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Verify the installation:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
explain-error --version
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Usage Guide
|
|
114
|
+
|
|
115
|
+
### 1. Command-Line Interface (CLI)
|
|
116
|
+
|
|
117
|
+
Run a Python script and catch any unhandled exceptions:
|
|
118
|
+
```bash
|
|
119
|
+
explain-error run script.py
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Provide an error string directly:
|
|
123
|
+
```bash
|
|
124
|
+
explain-error "NameError: name 'usr_count' is not defined"
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Pipe system or Docker logs into the engine:
|
|
128
|
+
```bash
|
|
129
|
+
cat error.log | explain-error
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### 2. Automatic Import Hook
|
|
133
|
+
|
|
134
|
+
Catch and translate unhandled exceptions globally by importing the module:
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
import error_translator.auto
|
|
138
|
+
|
|
139
|
+
def main():
|
|
140
|
+
# This TypeError will automatically trigger the error translator
|
|
141
|
+
total = "Users: " + 42
|
|
142
|
+
|
|
143
|
+
if __name__ == "__main__":
|
|
144
|
+
main()
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 3. FastAPI Service
|
|
148
|
+
|
|
149
|
+
Start the built-in HTTP server for remote translation services:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
uvicorn error_translator.server:app --host 127.0.0.1 --port 8000 --reload
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Submit a traceback payload via the exposed REST API:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
curl -X POST http://127.0.0.1:8000/translate \
|
|
159
|
+
-H "Content-Type: application/json" \
|
|
160
|
+
-d "{\"traceback_setting\":\"Traceback (most recent call last):\\n File 'app.py', line 14, in <module>\\n total = 'Users: ' + 42\\nTypeError: can only concatenate str (not 'int') to str\"}"
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Additional endpoints:
|
|
164
|
+
|
|
165
|
+
- `GET /health` returns service status.
|
|
166
|
+
- `GET /` serves the bundled web UI from `error_translator/static/index.html`.
|
|
167
|
+
|
|
168
|
+
## Documentation
|
|
169
|
+
|
|
170
|
+
Detailed documentation is located in the [`docs/`](docs/) directory:
|
|
171
|
+
|
|
172
|
+
- [**Real-World Examples**](docs/examples.md): Practical demonstrations comparing raw tracebacks with their translated counterparts.
|
|
173
|
+
- [**Architecture & Internals**](docs/ARCHITECTURE.md): Comprehensive teardown of the regex engine, AST integration, and internal design philosophy.
|
|
174
|
+
- [**Contributing Guidelines**](docs/CONTRIBUTING.md): Standards, PR checklists, and instructions for utilizing our AI-Powered Rule Builder.
|
|
175
|
+
|
|
176
|
+
## Maintainers
|
|
177
|
+
|
|
178
|
+
This project is actively developed and maintained by **Gourabananda Datta** alongside our open-source contributors.
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# Error Translator
|
|
2
|
+
|
|
3
|
+
<div align="left">
|
|
4
|
+
<a href="https://pypi.org/project/error-translator-cli-v2/"><img alt="PyPI Version" src="https://img.shields.io/pypi/v/error-translator-cli-v2.svg"></a>
|
|
5
|
+
<img alt="Python 3.9+" src="https://img.shields.io/badge/python-3.9%2B-blue.svg">
|
|
6
|
+
<a href="https://github.com/gourabanandad/error-translator-cli-v2/stargazers"><img alt="GitHub Stars" src="https://img.shields.io/github/stars/gourabanandad/error-translator-cli-v2?style=social"></a>
|
|
7
|
+
<a href="https://pypi.org/project/error-translator-cli-v2/"><img alt="PyPI Downloads" src="https://img.shields.io/pypi/dm/error-translator-cli-v2"></a>
|
|
8
|
+
<a href="https://github.com/gourabanandad/error-translator-cli-v2"><img alt="License" src="https://img.shields.io/github/license/gourabanandad/error-translator-cli-v2.svg"></a>
|
|
9
|
+
<a href="https://github.com/gourabanandad/error-translator-cli-v2/actions/workflows/ci.yml"><img alt="Build Status" src="https://img.shields.io/github/actions/workflow/status/gourabanandad/error-translator-cli-v2/ci.yml?branch=master&label=build"></a>
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
<br>
|
|
13
|
+
|
|
14
|
+
**Error Translator** is a powerful offline engine designed to parse raw Python tracebacks and translate them into crystal-clear explanations with immediately actionable fixes. Built with local-first development workflows in mind, it supports direct CLI usage, an automatic import hook, a programmatic Python API, and a FastAPI integration.
|
|
15
|
+
|
|
16
|
+
If this project saves you debugging time, please consider starring it on GitHub: https://github.com/gourabanandad/error-translator-cli-v2
|
|
17
|
+
|
|
18
|
+
## Why Developers Like It
|
|
19
|
+
|
|
20
|
+
* **Fast Feedback Loop**: Turn stack traces into direct next actions in seconds.
|
|
21
|
+
* **Works Offline**: No telemetry dependency for core translation behavior.
|
|
22
|
+
* **Beginner-Friendly Output**: Explanations are clear enough for learners, practical enough for teams.
|
|
23
|
+
* **Multiple Entry Points**: CLI, import hook, Python API, and FastAPI all share one deterministic engine.
|
|
24
|
+
|
|
25
|
+
## Key Features
|
|
26
|
+
|
|
27
|
+
* **CLI-First Architecture**: Seamlessly process scripts, direct error strings, or piped logs via the `explain-error` command.
|
|
28
|
+
* **Automatic Integration Mode**: Inject the module via `import error_translator.auto` to automatically override `sys.excepthook` for graceful, translated crash reporting.
|
|
29
|
+
* **Extensible API Surfaces**: Integrate natively within Python or expose the core engine over HTTP via the included FastAPI server.
|
|
30
|
+
* **Deterministic Rules Engine**: High-performance, regex-based matching powered by `rules.json` guarantees offline and privacy-first translations.
|
|
31
|
+
* **Optional AST Insight Hooks**: Registered handlers can append targeted hints (`ast_insight`) for selected error types.
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
Python requirement: **3.9 or newer**.
|
|
36
|
+
|
|
37
|
+
Install the latest stable release directly from PyPI:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install error-translator-cli-v2
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Verify the installation:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
explain-error --version
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Usage Guide
|
|
50
|
+
|
|
51
|
+
### 1. Command-Line Interface (CLI)
|
|
52
|
+
|
|
53
|
+
Run a Python script and catch any unhandled exceptions:
|
|
54
|
+
```bash
|
|
55
|
+
explain-error run script.py
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Provide an error string directly:
|
|
59
|
+
```bash
|
|
60
|
+
explain-error "NameError: name 'usr_count' is not defined"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Pipe system or Docker logs into the engine:
|
|
64
|
+
```bash
|
|
65
|
+
cat error.log | explain-error
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 2. Automatic Import Hook
|
|
69
|
+
|
|
70
|
+
Catch and translate unhandled exceptions globally by importing the module:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
import error_translator.auto
|
|
74
|
+
|
|
75
|
+
def main():
|
|
76
|
+
# This TypeError will automatically trigger the error translator
|
|
77
|
+
total = "Users: " + 42
|
|
78
|
+
|
|
79
|
+
if __name__ == "__main__":
|
|
80
|
+
main()
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 3. FastAPI Service
|
|
84
|
+
|
|
85
|
+
Start the built-in HTTP server for remote translation services:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
uvicorn error_translator.server:app --host 127.0.0.1 --port 8000 --reload
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Submit a traceback payload via the exposed REST API:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
curl -X POST http://127.0.0.1:8000/translate \
|
|
95
|
+
-H "Content-Type: application/json" \
|
|
96
|
+
-d "{\"traceback_setting\":\"Traceback (most recent call last):\\n File 'app.py', line 14, in <module>\\n total = 'Users: ' + 42\\nTypeError: can only concatenate str (not 'int') to str\"}"
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Additional endpoints:
|
|
100
|
+
|
|
101
|
+
- `GET /health` returns service status.
|
|
102
|
+
- `GET /` serves the bundled web UI from `error_translator/static/index.html`.
|
|
103
|
+
|
|
104
|
+
## Documentation
|
|
105
|
+
|
|
106
|
+
Detailed documentation is located in the [`docs/`](docs/) directory:
|
|
107
|
+
|
|
108
|
+
- [**Real-World Examples**](docs/examples.md): Practical demonstrations comparing raw tracebacks with their translated counterparts.
|
|
109
|
+
- [**Architecture & Internals**](docs/ARCHITECTURE.md): Comprehensive teardown of the regex engine, AST integration, and internal design philosophy.
|
|
110
|
+
- [**Contributing Guidelines**](docs/CONTRIBUTING.md): Standards, PR checklists, and instructions for utilizing our AI-Powered Rule Builder.
|
|
111
|
+
|
|
112
|
+
## Maintainers
|
|
113
|
+
|
|
114
|
+
This project is actively developed and maintained by **Gourabananda Datta** alongside our open-source contributors.
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import sys
|
|
2
2
|
import argparse
|
|
3
3
|
from .core import translate_error
|
|
4
|
+
from importlib.metadata import version, PackageNotFoundError
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
VERSION = version("error-translator-cli-v2")
|
|
8
|
+
except PackageNotFoundError:
|
|
9
|
+
VERSION = "unknown (not installed via pip)" # Fallback version if package metadata is not found
|
|
4
10
|
|
|
5
11
|
# ANSI Color Codes
|
|
6
12
|
class Colors:
|
|
@@ -12,6 +18,32 @@ class Colors:
|
|
|
12
18
|
RESET = '\033[0m'
|
|
13
19
|
MAGENTA = '\033[95m'
|
|
14
20
|
|
|
21
|
+
|
|
22
|
+
def print_about():
|
|
23
|
+
"""Prints the about message for the tool."""
|
|
24
|
+
about_text = f"""
|
|
25
|
+
ERROR TRANSLATOR CLI
|
|
26
|
+
=====================
|
|
27
|
+
A lightning-fast, offline tool that translates raw Python tracebacks
|
|
28
|
+
into human-readable explanations with actionable fixes.
|
|
29
|
+
|
|
30
|
+
Authors: Gourabananda Datta
|
|
31
|
+
Repository: https://github.com/gourabanandad/error-translator-cli-v2
|
|
32
|
+
Usage:
|
|
33
|
+
1. Run a script and translate its errors:
|
|
34
|
+
explain-error run your_script.py
|
|
35
|
+
2. Translate an error message directly:
|
|
36
|
+
explain-error "TypeError: unsupported operand type(s) for +: 'int' and 'str'"
|
|
37
|
+
3. Pipe an error log:
|
|
38
|
+
cat error.log | explain-error
|
|
39
|
+
4. Get help:
|
|
40
|
+
explain-error --help
|
|
41
|
+
5. About:
|
|
42
|
+
explain-error --about
|
|
43
|
+
"""
|
|
44
|
+
print(f"\033[96m{about_text}\033[0m")
|
|
45
|
+
|
|
46
|
+
|
|
15
47
|
def print_result(result: dict):
|
|
16
48
|
"""Prints the translated error to the terminal with colors."""
|
|
17
49
|
print(f"\n{Colors.RED}{Colors.BOLD} Error Detected:{Colors.RESET}")
|
|
@@ -68,18 +100,58 @@ def run_script(script_name: str):
|
|
|
68
100
|
# Entry point of the program
|
|
69
101
|
def main():
|
|
70
102
|
parser = argparse.ArgumentParser(
|
|
71
|
-
|
|
103
|
+
prog="explain-error",
|
|
104
|
+
description="Error Translator — Turn cryptic Python tracebacks into clear, actionable advice.",
|
|
105
|
+
epilog="""
|
|
106
|
+
Examples:
|
|
107
|
+
# Run a Python script and translate any unhandled errors
|
|
108
|
+
explain-error run my_script.py
|
|
109
|
+
|
|
110
|
+
# Translate a raw error string directly
|
|
111
|
+
explain-error "NameError: name 'usr_count' is not defined"
|
|
112
|
+
|
|
113
|
+
# Pipe a traceback from a log file or another command
|
|
114
|
+
cat error.log | explain-error
|
|
115
|
+
|
|
116
|
+
For more information, visit: https://github.com/gourabanandad/error-translator
|
|
117
|
+
""",
|
|
118
|
+
formatter_class=argparse.RawDescriptionHelpFormatter
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
parser.add_argument(
|
|
122
|
+
"-a",
|
|
123
|
+
"--about",
|
|
124
|
+
action="store_true",
|
|
125
|
+
help="Display information about the tool."
|
|
72
126
|
)
|
|
73
127
|
|
|
74
|
-
# Allow multiple arguments so we can accept "run script.py" or a long error string
|
|
75
128
|
parser.add_argument(
|
|
76
|
-
"
|
|
77
|
-
|
|
78
|
-
|
|
129
|
+
"-v",
|
|
130
|
+
"--version",
|
|
131
|
+
action="store_true",
|
|
132
|
+
help="Show the current version of the tool."
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
parser.add_argument(
|
|
136
|
+
"args",
|
|
137
|
+
nargs="*",
|
|
138
|
+
help=(
|
|
139
|
+
"Positional arguments. Use 'run <script.py>' to execute a Python file, "
|
|
140
|
+
"or provide an error string to translate. If no arguments are given and "
|
|
141
|
+
"stdin is not piped, this help message is displayed."
|
|
142
|
+
)
|
|
79
143
|
)
|
|
80
144
|
|
|
81
145
|
parsed_args = parser.parse_args()
|
|
82
146
|
|
|
147
|
+
if parsed_args.about:
|
|
148
|
+
print_about()
|
|
149
|
+
sys.exit(0)
|
|
150
|
+
|
|
151
|
+
if parsed_args.version:
|
|
152
|
+
print(f"Error Translator CLI Version: {Colors.GREEN}{VERSION}{Colors.RESET}")
|
|
153
|
+
sys.exit(0)
|
|
154
|
+
|
|
83
155
|
# 1. Handle Piped Input (e.g., cat error.log | explain-error)
|
|
84
156
|
if not sys.stdin.isatty():
|
|
85
157
|
error_input = sys.stdin.read()
|
|
@@ -87,7 +159,7 @@ def main():
|
|
|
87
159
|
print_result(translate_error(error_input))
|
|
88
160
|
return
|
|
89
161
|
|
|
90
|
-
# 2. Print help if no arguments
|
|
162
|
+
# 2. Print help if no arguments and no piped input
|
|
91
163
|
if not parsed_args.args:
|
|
92
164
|
parser.print_help()
|
|
93
165
|
sys.exit(1)
|
|
@@ -96,11 +168,11 @@ def main():
|
|
|
96
168
|
if parsed_args.args[0] == "run" and len(parsed_args.args) > 1:
|
|
97
169
|
script_name = parsed_args.args[1]
|
|
98
170
|
run_script(script_name)
|
|
99
|
-
|
|
171
|
+
|
|
100
172
|
# 4. Fallback: Treat the input as a raw error string
|
|
101
173
|
else:
|
|
102
174
|
error_input = " ".join(parsed_args.args)
|
|
103
175
|
print_result(translate_error(error_input))
|
|
104
176
|
|
|
105
177
|
if __name__ == "__main__":
|
|
106
|
-
main()
|
|
178
|
+
main()
|