error-translator-cli-v2 1.0.0__tar.gz → 1.0.1__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 (15) hide show
  1. {error_translator_cli_v2-1.0.0 → error_translator_cli_v2-1.0.1}/PKG-INFO +26 -8
  2. {error_translator_cli_v2-1.0.0 → error_translator_cli_v2-1.0.1}/README.md +25 -7
  3. {error_translator_cli_v2-1.0.0 → error_translator_cli_v2-1.0.1}/error_translator/cli.py +7 -0
  4. {error_translator_cli_v2-1.0.0 → error_translator_cli_v2-1.0.1}/error_translator/core.py +18 -5
  5. {error_translator_cli_v2-1.0.0 → error_translator_cli_v2-1.0.1}/error_translator_cli_v2.egg-info/PKG-INFO +26 -8
  6. {error_translator_cli_v2-1.0.0 → error_translator_cli_v2-1.0.1}/pyproject.toml +1 -1
  7. {error_translator_cli_v2-1.0.0 → error_translator_cli_v2-1.0.1}/tests/test_core.py +1 -1
  8. {error_translator_cli_v2-1.0.0 → error_translator_cli_v2-1.0.1}/error_translator/__init__.py +0 -0
  9. {error_translator_cli_v2-1.0.0 → error_translator_cli_v2-1.0.1}/error_translator/auto.py +0 -0
  10. {error_translator_cli_v2-1.0.0 → error_translator_cli_v2-1.0.1}/error_translator/rules.py +0 -0
  11. {error_translator_cli_v2-1.0.0 → error_translator_cli_v2-1.0.1}/error_translator_cli_v2.egg-info/SOURCES.txt +0 -0
  12. {error_translator_cli_v2-1.0.0 → error_translator_cli_v2-1.0.1}/error_translator_cli_v2.egg-info/dependency_links.txt +0 -0
  13. {error_translator_cli_v2-1.0.0 → error_translator_cli_v2-1.0.1}/error_translator_cli_v2.egg-info/entry_points.txt +0 -0
  14. {error_translator_cli_v2-1.0.0 → error_translator_cli_v2-1.0.1}/error_translator_cli_v2.egg-info/top_level.txt +0 -0
  15. {error_translator_cli_v2-1.0.0 → error_translator_cli_v2-1.0.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: error-translator-cli-v2
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: A CLI tool that explains Python errors in simple human language.
5
5
  Author-email: Gourabananda Datta <gourabanandadatta@zohomail.com>
6
6
  Requires-Python: >=3.7
@@ -32,19 +32,37 @@ pip install error-translator-cli-v2
32
32
 
33
33
  🚀 Usage
34
34
 
35
- Simply pass your Python error message or traceback as a string to the explain-error command.
35
+ You can use the Error Translator in three different ways:
36
36
 
37
- Example 1: NameError with Full Traceback
37
+ ### 1. Magic Import (Recommended)
38
+ Simply add this single import at the top of your Python script. If your script crashes, it will automatically intercept and translate the error!
38
39
 
39
- explain-error "Traceback (most recent call last):
40
- File 'script.py', line 2, in <module>
41
- print(my_variable)
42
- NameError: name 'my_variable' is not defined"
40
+ ```python
41
+ import error_translator.auto
43
42
 
43
+ # Your normal code...
44
+ math_is_broken = 10 / 0 # This crash will be automatically translated!
45
+ ```
44
46
 
45
- Example 2: Quick TypeError
47
+ ### 2. Run Scripts via CLI
48
+ You can execute your python files directly through the CLI tool. It will run your program normally and intercept any crashes.
46
49
 
50
+ ```bash
51
+ explain-error run script.py
52
+ ```
53
+
54
+ ### 3. Translate Raw Error Strings
55
+ You can pass errors as a string or pipe them from another command.
56
+
57
+ **Pass directly:**
58
+ ```bash
47
59
  explain-error "TypeError: unsupported operand type(s) for +: 'int' and 'str'"
60
+ ```
61
+
62
+ **Pipe from a file:**
63
+ ```bash
64
+ cat error.log | explain-error
65
+ ```
48
66
 
49
67
 
50
68
  🧠 Supported Errors
@@ -24,19 +24,37 @@ pip install error-translator-cli-v2
24
24
 
25
25
  🚀 Usage
26
26
 
27
- Simply pass your Python error message or traceback as a string to the explain-error command.
27
+ You can use the Error Translator in three different ways:
28
28
 
29
- Example 1: NameError with Full Traceback
29
+ ### 1. Magic Import (Recommended)
30
+ Simply add this single import at the top of your Python script. If your script crashes, it will automatically intercept and translate the error!
30
31
 
31
- explain-error "Traceback (most recent call last):
32
- File 'script.py', line 2, in <module>
33
- print(my_variable)
34
- NameError: name 'my_variable' is not defined"
32
+ ```python
33
+ import error_translator.auto
35
34
 
35
+ # Your normal code...
36
+ math_is_broken = 10 / 0 # This crash will be automatically translated!
37
+ ```
36
38
 
37
- Example 2: Quick TypeError
39
+ ### 2. Run Scripts via CLI
40
+ You can execute your python files directly through the CLI tool. It will run your program normally and intercept any crashes.
38
41
 
42
+ ```bash
43
+ explain-error run script.py
44
+ ```
45
+
46
+ ### 3. Translate Raw Error Strings
47
+ You can pass errors as a string or pipe them from another command.
48
+
49
+ **Pass directly:**
50
+ ```bash
39
51
  explain-error "TypeError: unsupported operand type(s) for +: 'int' and 'str'"
52
+ ```
53
+
54
+ **Pipe from a file:**
55
+ ```bash
56
+ cat error.log | explain-error
57
+ ```
40
58
 
41
59
 
42
60
  🧠 Supported Errors
@@ -18,6 +18,13 @@ def print_result(result: dict):
18
18
 
19
19
  if "file" in result:
20
20
  print(f"{Colors.YELLOW} Location: {result['file']} (Line {result['line']}){Colors.RESET}\n")
21
+ if result.get("code"):
22
+ print(f"{Colors.RESET} |")
23
+ print(f"{Colors.RESET} | {Colors.RED}{result['code']}{Colors.RESET}")
24
+ print(f"{Colors.RESET} |\n")
25
+ else:
26
+ print("\n")
27
+
21
28
  else:
22
29
  print()
23
30
 
@@ -12,7 +12,8 @@ def load_rules():
12
12
  return json.load(file)
13
13
 
14
14
  def translate_error(traceback_text: str) -> dict:
15
- import re # Lazy import
15
+ import re
16
+ import linecache # <-- NEW: Lazy import the linecache module
16
17
 
17
18
  data = load_rules()
18
19
  rules = data["rules"]
@@ -24,13 +25,23 @@ def translate_error(traceback_text: str) -> dict:
24
25
 
25
26
  actual_error_line = lines[-1]
26
27
 
27
- # Flexible regex to catch single or double quotes, and handle missing ones
28
28
  location_match = re.search(r'File\s+[\'"]?(.*?)[\'"]?,\s+line\s+(\d+)', traceback_text)
29
29
  file_name = location_match.group(1) if location_match else "Unknown File"
30
30
  line_number = location_match.group(2) if location_match else "Unknown Line"
31
31
 
32
+ # --- NEW CONTEXT ENGINE LOGIC ---
33
+ code_context = ""
34
+ if file_name != "Unknown File" and line_number != "Unknown Line":
35
+ try:
36
+ # linecache safely fetches the exact line of code as a string
37
+ raw_line = linecache.getline(file_name, int(line_number))
38
+ if raw_line:
39
+ code_context = raw_line.strip() # Remove extra spaces/newlines
40
+ except Exception:
41
+ pass # If the file can't be read for any reason, fail silently
42
+ # --------------------------------
43
+
32
44
  for rule in rules:
33
- # Compile the regex pattern on the fly
34
45
  pattern = re.compile(rule["pattern"])
35
46
  match = pattern.search(actual_error_line)
36
47
 
@@ -41,7 +52,8 @@ def translate_error(traceback_text: str) -> dict:
41
52
  "fix": rule["fix"].format(*extracted_values),
42
53
  "matched_error": actual_error_line,
43
54
  "file": file_name,
44
- "line": line_number
55
+ "line": line_number,
56
+ "code": code_context
45
57
  }
46
58
 
47
59
  return {
@@ -49,5 +61,6 @@ def translate_error(traceback_text: str) -> dict:
49
61
  "fix": default_error["fix"],
50
62
  "matched_error": actual_error_line,
51
63
  "file": file_name,
52
- "line": line_number
64
+ "line": line_number,
65
+ "code": code_context
53
66
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: error-translator-cli-v2
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: A CLI tool that explains Python errors in simple human language.
5
5
  Author-email: Gourabananda Datta <gourabanandadatta@zohomail.com>
6
6
  Requires-Python: >=3.7
@@ -32,19 +32,37 @@ pip install error-translator-cli-v2
32
32
 
33
33
  🚀 Usage
34
34
 
35
- Simply pass your Python error message or traceback as a string to the explain-error command.
35
+ You can use the Error Translator in three different ways:
36
36
 
37
- Example 1: NameError with Full Traceback
37
+ ### 1. Magic Import (Recommended)
38
+ Simply add this single import at the top of your Python script. If your script crashes, it will automatically intercept and translate the error!
38
39
 
39
- explain-error "Traceback (most recent call last):
40
- File 'script.py', line 2, in <module>
41
- print(my_variable)
42
- NameError: name 'my_variable' is not defined"
40
+ ```python
41
+ import error_translator.auto
43
42
 
43
+ # Your normal code...
44
+ math_is_broken = 10 / 0 # This crash will be automatically translated!
45
+ ```
44
46
 
45
- Example 2: Quick TypeError
47
+ ### 2. Run Scripts via CLI
48
+ You can execute your python files directly through the CLI tool. It will run your program normally and intercept any crashes.
46
49
 
50
+ ```bash
51
+ explain-error run script.py
52
+ ```
53
+
54
+ ### 3. Translate Raw Error Strings
55
+ You can pass errors as a string or pipe them from another command.
56
+
57
+ **Pass directly:**
58
+ ```bash
47
59
  explain-error "TypeError: unsupported operand type(s) for +: 'int' and 'str'"
60
+ ```
61
+
62
+ **Pipe from a file:**
63
+ ```bash
64
+ cat error.log | explain-error
65
+ ```
48
66
 
49
67
 
50
68
  🧠 Supported Errors
@@ -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.0"
7
+ version = "1.0.1"
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,4 +1,4 @@
1
- import error_translator.auto
1
+ from error_translator.core import translate_error
2
2
 
3
3
  def test_name_error_translation_double_quotes():
4
4
  """Test standard traceback with double quotes around the filename."""