File size: 1,138 Bytes
f18435c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# cli.py

import sys
from explain_error import explain_error

def main():
    if len(sys.argv) != 2:
        print("Usage: python cli.py <path_to_jenkins_error_log>")
        sys.exit(1)

    log_path = sys.argv[1]

    try:
        with open(log_path, "r", encoding="utf-8") as f:
            log_text = f.read()
    except FileNotFoundError:
        print(f"Error: File not found -> {log_path}")
        sys.exit(1)

    result = explain_error(log_text)

    if result["error_category"] == "unknown":
        print(
            "Warning: This error is not currently supported by the explainer. "
            "The explanation may be incomplete.\n"
        )

    print("\n=== Jenkins Error Explanation ===\n")
    print(f"Error Category:\n{result['error_category']}\n")

    print("Error Summary:")
    print(result["summary"], "\n")

    print("Likely Causes:")
    for cause in result["likely_causes"]:
        print(f"- {cause}")
    print()

    print("Relevant Documentation:")
    for ref in result["references"]:
        print(f"- {ref}")

    print("\n================================\n")


if __name__ == "__main__":
    main()