Upload explain_error.py with huggingface_hub
Browse files123456789101111 unmodified lines232425262728293031324 unmodified lines373839404142434445464 unmodified lines515253545556575859604 unmodified lines656667686970717273743 unmodified lines787980818283848586874 unmodified lines92939495969798991001013 unmodified lines105106107108109110111112113114115116117118119120121122123124125126127# explain_error.pyfrom extract_error_features import extract_error_featuresdef explain_error(log_text: str):features = extract_error_features(log_text)category = features["category"]explanation = {"error_category": category,"summary": "",11 unmodified lines"Missing or mismatched braces in the Jenkinsfile","Invalid declarative pipeline structure"]explanation["references"] = ["Pipeline Syntax Reference (Jenkins.io)","Declarative Pipeline Documentation"]elif category == "missing_agent":explanation["summary"] = (4 unmodified lines"Using 'agent none' without defining a stage-level agent","Executing node-dependent steps without a workspace"]explanation["references"] = ["Agent Directive (Jenkins.io)","Pipeline Steps Documentation"]elif category == "no_node_available":explanation["summary"] = (4 unmodified lines"The specified node label does not exist","All matching nodes are offline or busy"]explanation["references"] = ["Distributed Builds (Jenkins.io)","Node Label Plugin Documentation"]elif category == "missing_plugin":explanation["summary"] = (4 unmodified lines"Required plugin is not installed","Incorrect step name in the Jenkinsfile"]explanation["references"] = ["Plugin Index","Pipeline Steps Reference"]elif category == "missing_credentials":explanation["summary"] = (3 unmodified lines"Credentials ID is incorrect or misspelled","Credentials were not configured in Jenkins"]explanation["references"] = ["Credentials Plugin Documentation","Using Credentials in Pipelines"]elif category == "file_not_found":explanation["summary"] = (4 unmodified lines"File path is incorrect","File was not generated or checked out"]explanation["references"] = ["Pipeline Basic Steps","Workspace Plugin Documentation"]elif category == "git_authentication_error":explanation["summary"] = (3 unmodified lines"Invalid or missing Git credentials","Repository requires token-based authentication"]explanation["references"] = ["Git Plugin Documentation","Credential Binding Plugin"]else:explanation["summary"] = ("The error could not be confidently identified. ""Please check the error message for more details.")explanation["likely_causes"] = ["Review the full error log","Check Jenkins system logs"]explanation["references"] = ["Jenkins Pipeline Troubleshooting Guide"]return explanation12345678910111213141516171819202122232425262728293031323311 unmodified lines4546474849504 unmodified lines5556575859604 unmodified lines6566676869704 unmodified lines7576777879803 unmodified lines8485868788894 unmodified lines9495969798993 unmodified lines103104105106107108109110111112113114115116117118119120121122123124125# explain_error.pyfrom extract_error_features import extract_error_featuresfrom retrieve_docs import retrieve_docsSYSTEM_PROMPT = """You are a Jenkins CI/CD expert.Explain the Jenkins error using ONLY the provided documentation context.If the documentation does not clearly explain the error, say so explicitly.Output format:Error Summary:<short explanation>Likely Causes:- cause 1- cause 2Relevant Documentation:- link or source file"""def explain_error(log_text: str):features = extract_error_features(log_text)category = features["category"]retrieved = retrieve_docs(category)explanation = {"error_category": category,"summary": "",11 unmodified lines"Missing or mismatched braces in the Jenkinsfile","Invalid declarative pipeline structure"]elif category == "missing_agent":explanation["summary"] = (4 unmodified lines"Using 'agent none' without defining a stage-level agent","Executing node-dependent steps without a workspace"]elif category == "no_node_available":explanation["summary"] = (4 unmodified lines"The specified node label does not exist","All matching nodes are offline or busy"]elif category == "missing_plugin":explanation["summary"] = (4 unmodified lines"Required plugin is not installed","Incorrect step name in the Jenkinsfile"]elif category == "missing_credentials":explanation["summary"] = (3 unmodified lines"Credentials ID is incorrect or misspelled","Credentials were not configured in Jenkins"]elif category == "file_not_found":explanation["summary"] = (4 unmodified lines"File path is incorrect","File was not generated or checked out"]elif category == "git_authentication_error":explanation["summary"] = (3 unmodified lines"Invalid or missing Git credentials","Repository requires token-based authentication"]else:explanation["summary"] = ("The error could not be confidently explained using the available documentation.")for r in retrieved:explanation["references"].append(f"{r['meta']['source_file']} ({r['meta']['source']})")if not retrieved:explanation["summary"] = ("No relevant Jenkins documentation was found for this error. ""The error may be plugin-specific or outside the current scope.")explanation["likely_causes"] = []explanation["references"] = []return explanation
explain_error.py+35-37