-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path09_error_stack_resolver.py
More file actions
51 lines (40 loc) · 1.31 KB
/
Copy path09_error_stack_resolver.py
File metadata and controls
51 lines (40 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import argparse
import os
import sys
from google import genai
from dotenv import load_dotenv
load_dotenv()
def resolve_error(traceback):
client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))
prompt = f"""
Analyze the following error traceback. Identify the root cause and provide a step-by-step fix.
Traceback:
{traceback}
"""
try:
print("=== Analyzing Error ===")
response = client.models.generate_content(
model="gemini-2.0-flash",
contents=prompt
)
print(response.text)
except Exception as e:
print(f"Error: {e}")
def main():
parser = argparse.ArgumentParser(description="Error Stack Resolver CLI")
# Using nargs='?' to allow piping or direct argument
parser.add_argument("traceback", nargs="?", help="The raw error traceback string")
args = parser.parse_args()
traceback = args.traceback
if not traceback:
if not sys.stdin.isatty():
traceback = sys.stdin.read()
else:
print("Error: No traceback provided. Please provide it as an argument or pipe it.")
sys.exit(1)
if not os.getenv("GEMINI_API_KEY"):
print("Error: GEMINI_API_KEY not found.")
sys.exit(1)
resolve_error(traceback)
if __name__ == "__main__":
main()