Arvind2006 commited on
Commit
d520cc3
·
verified ·
1 Parent(s): d46efa7

Upload explain_error.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. explain_error.py +35 -37
explain_error.py CHANGED
@@ -1,11 +1,33 @@
1
  # explain_error.py
2
 
3
  from extract_error_features import extract_error_features
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  def explain_error(log_text: str):
6
  features = extract_error_features(log_text)
7
  category = features["category"]
8
 
 
 
9
  explanation = {
10
  "error_category": category,
11
  "summary": "",
@@ -23,10 +45,6 @@ def explain_error(log_text: str):
23
  "Missing or mismatched braces in the Jenkinsfile",
24
  "Invalid declarative pipeline structure"
25
  ]
26
- explanation["references"] = [
27
- "Pipeline Syntax Reference (Jenkins.io)",
28
- "Declarative Pipeline Documentation"
29
- ]
30
 
31
  elif category == "missing_agent":
32
  explanation["summary"] = (
@@ -37,10 +55,6 @@ def explain_error(log_text: str):
37
  "Using 'agent none' without defining a stage-level agent",
38
  "Executing node-dependent steps without a workspace"
39
  ]
40
- explanation["references"] = [
41
- "Agent Directive (Jenkins.io)",
42
- "Pipeline Steps Documentation"
43
- ]
44
 
45
  elif category == "no_node_available":
46
  explanation["summary"] = (
@@ -51,10 +65,6 @@ def explain_error(log_text: str):
51
  "The specified node label does not exist",
52
  "All matching nodes are offline or busy"
53
  ]
54
- explanation["references"] = [
55
- "Distributed Builds (Jenkins.io)",
56
- "Node Label Plugin Documentation"
57
- ]
58
 
59
  elif category == "missing_plugin":
60
  explanation["summary"] = (
@@ -65,10 +75,6 @@ def explain_error(log_text: str):
65
  "Required plugin is not installed",
66
  "Incorrect step name in the Jenkinsfile"
67
  ]
68
- explanation["references"] = [
69
- "Plugin Index",
70
- "Pipeline Steps Reference"
71
- ]
72
 
73
  elif category == "missing_credentials":
74
  explanation["summary"] = (
@@ -78,10 +84,6 @@ def explain_error(log_text: str):
78
  "Credentials ID is incorrect or misspelled",
79
  "Credentials were not configured in Jenkins"
80
  ]
81
- explanation["references"] = [
82
- "Credentials Plugin Documentation",
83
- "Using Credentials in Pipelines"
84
- ]
85
 
86
  elif category == "file_not_found":
87
  explanation["summary"] = (
@@ -92,10 +94,6 @@ def explain_error(log_text: str):
92
  "File path is incorrect",
93
  "File was not generated or checked out"
94
  ]
95
- explanation["references"] = [
96
- "Pipeline Basic Steps",
97
- "Workspace Plugin Documentation"
98
- ]
99
 
100
  elif category == "git_authentication_error":
101
  explanation["summary"] = (
@@ -105,23 +103,23 @@ def explain_error(log_text: str):
105
  "Invalid or missing Git credentials",
106
  "Repository requires token-based authentication"
107
  ]
108
- explanation["references"] = [
109
- "Git Plugin Documentation",
110
- "Credential Binding Plugin"
111
- ]
112
 
113
  else:
114
  explanation["summary"] = (
115
- "The error could not be confidently identified. "
116
- "Please check the error message for more details."
117
  )
118
- explanation["likely_causes"] = [
119
- "Review the full error log",
120
- "Check Jenkins system logs"
121
- ]
122
- explanation["references"] = [
123
- "Jenkins Pipeline Troubleshooting Guide"
124
- ]
 
 
 
 
 
125
 
126
  return explanation
127
 
 
1
  # explain_error.py
2
 
3
  from extract_error_features import extract_error_features
4
+ from retrieve_docs import retrieve_docs
5
+
6
+ SYSTEM_PROMPT = """
7
+ You are a Jenkins CI/CD expert.
8
+
9
+ Explain the Jenkins error using ONLY the provided documentation context.
10
+ If the documentation does not clearly explain the error, say so explicitly.
11
+
12
+ Output format:
13
+
14
+ Error Summary:
15
+ <short explanation>
16
+
17
+ Likely Causes:
18
+ - cause 1
19
+ - cause 2
20
+
21
+ Relevant Documentation:
22
+ - link or source file
23
+ """
24
 
25
  def explain_error(log_text: str):
26
  features = extract_error_features(log_text)
27
  category = features["category"]
28
 
29
+ retrieved = retrieve_docs(category)
30
+
31
  explanation = {
32
  "error_category": category,
33
  "summary": "",
 
45
  "Missing or mismatched braces in the Jenkinsfile",
46
  "Invalid declarative pipeline structure"
47
  ]
 
 
 
 
48
 
49
  elif category == "missing_agent":
50
  explanation["summary"] = (
 
55
  "Using 'agent none' without defining a stage-level agent",
56
  "Executing node-dependent steps without a workspace"
57
  ]
 
 
 
 
58
 
59
  elif category == "no_node_available":
60
  explanation["summary"] = (
 
65
  "The specified node label does not exist",
66
  "All matching nodes are offline or busy"
67
  ]
 
 
 
 
68
 
69
  elif category == "missing_plugin":
70
  explanation["summary"] = (
 
75
  "Required plugin is not installed",
76
  "Incorrect step name in the Jenkinsfile"
77
  ]
 
 
 
 
78
 
79
  elif category == "missing_credentials":
80
  explanation["summary"] = (
 
84
  "Credentials ID is incorrect or misspelled",
85
  "Credentials were not configured in Jenkins"
86
  ]
 
 
 
 
87
 
88
  elif category == "file_not_found":
89
  explanation["summary"] = (
 
94
  "File path is incorrect",
95
  "File was not generated or checked out"
96
  ]
 
 
 
 
97
 
98
  elif category == "git_authentication_error":
99
  explanation["summary"] = (
 
103
  "Invalid or missing Git credentials",
104
  "Repository requires token-based authentication"
105
  ]
 
 
 
 
106
 
107
  else:
108
  explanation["summary"] = (
109
+ "The error could not be confidently explained using the available documentation."
 
110
  )
111
+
112
+ for r in retrieved:
113
+ explanation["references"].append(
114
+ f"{r['meta']['source_file']} ({r['meta']['source']})"
115
+ )
116
+ if not retrieved:
117
+ explanation["summary"] = (
118
+ "No relevant Jenkins documentation was found for this error. "
119
+ "The error may be plugin-specific or outside the current scope."
120
+ )
121
+ explanation["likely_causes"] = []
122
+ explanation["references"] = []
123
 
124
  return explanation
125