error-translator-cli-v2 1.1.3__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.3 → error_translator_cli_v2-1.1.4}/error_translator/cli.py +34 -21
- 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.3 → 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.3/PKG-INFO +0 -243
- error_translator_cli_v2-1.1.3/README.md +0 -232
- error_translator_cli_v2-1.1.3/error_translator/server.py +0 -25
- error_translator_cli_v2-1.1.3/error_translator_cli_v2.egg-info/PKG-INFO +0 -243
- error_translator_cli_v2-1.1.3/pyproject.toml +0 -23
- {error_translator_cli_v2-1.1.3 → error_translator_cli_v2-1.1.4}/error_translator/__init__.py +0 -0
- {error_translator_cli_v2-1.1.3 → error_translator_cli_v2-1.1.4}/error_translator/ast_handlers.py +0 -0
- {error_translator_cli_v2-1.1.3 → error_translator_cli_v2-1.1.4}/error_translator/auto.py +0 -0
- {error_translator_cli_v2-1.1.3 → error_translator_cli_v2-1.1.4}/error_translator/core.py +0 -0
- {error_translator_cli_v2-1.1.3 → error_translator_cli_v2-1.1.4}/error_translator_cli_v2.egg-info/dependency_links.txt +0 -0
- {error_translator_cli_v2-1.1.3 → error_translator_cli_v2-1.1.4}/error_translator_cli_v2.egg-info/entry_points.txt +0 -0
- {error_translator_cli_v2-1.1.3 → error_translator_cli_v2-1.1.4}/error_translator_cli_v2.egg-info/top_level.txt +0 -0
- {error_translator_cli_v2-1.1.3 → error_translator_cli_v2-1.1.4}/setup.cfg +0 -0
- {error_translator_cli_v2-1.1.3 → 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.
|
|
@@ -101,9 +101,21 @@ def run_script(script_name: str):
|
|
|
101
101
|
def main():
|
|
102
102
|
parser = argparse.ArgumentParser(
|
|
103
103
|
prog="explain-error",
|
|
104
|
-
description="
|
|
105
|
-
epilog="
|
|
106
|
-
|
|
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
|
|
107
119
|
)
|
|
108
120
|
|
|
109
121
|
parser.add_argument(
|
|
@@ -119,11 +131,15 @@ def main():
|
|
|
119
131
|
action="store_true",
|
|
120
132
|
help="Show the current version of the tool."
|
|
121
133
|
)
|
|
122
|
-
|
|
134
|
+
|
|
123
135
|
parser.add_argument(
|
|
124
|
-
"args",
|
|
125
|
-
nargs="*",
|
|
126
|
-
help=
|
|
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
|
+
)
|
|
127
143
|
)
|
|
128
144
|
|
|
129
145
|
parsed_args = parser.parse_args()
|
|
@@ -143,23 +159,20 @@ def main():
|
|
|
143
159
|
print_result(translate_error(error_input))
|
|
144
160
|
return
|
|
145
161
|
|
|
146
|
-
# 2. Print help if no arguments
|
|
162
|
+
# 2. Print help if no arguments and no piped input
|
|
147
163
|
if not parsed_args.args:
|
|
148
164
|
parser.print_help()
|
|
149
165
|
sys.exit(1)
|
|
150
166
|
|
|
151
|
-
if
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
# 4. Fallback: Treat the input as a raw error string
|
|
158
|
-
else:
|
|
159
|
-
error_input = " ".join(parsed_args.args)
|
|
160
|
-
print_result(translate_error(error_input))
|
|
167
|
+
# 3. Check if the user used the "run" command
|
|
168
|
+
if parsed_args.args[0] == "run" and len(parsed_args.args) > 1:
|
|
169
|
+
script_name = parsed_args.args[1]
|
|
170
|
+
run_script(script_name)
|
|
171
|
+
|
|
172
|
+
# 4. Fallback: Treat the input as a raw error string
|
|
161
173
|
else:
|
|
162
|
-
|
|
163
|
-
|
|
174
|
+
error_input = " ".join(parsed_args.args)
|
|
175
|
+
print_result(translate_error(error_input))
|
|
176
|
+
|
|
164
177
|
if __name__ == "__main__":
|
|
165
|
-
main()
|
|
178
|
+
main()
|