MCPcopy Create free account
hub / github.com/agenticsorg/edge-agents / handle_cli_error

Function handle_cli_error

scripts/agents/devops/src/cli.py:59–116  ·  view source on GitHub ↗

Handle CLI errors with user-friendly messages. Args: error: The exception that was raised Returns: Exit code to return from the command

(error: Exception)

Source from the content-addressed store, hash-verified

57 print(f"\n{COLORS['yellow']}SUGGESTION: {suggestion}{COLORS['reset']}")
58
59def handle_cli_error(error: Exception) -> int:
60 """
61 Handle CLI errors with user-friendly messages.
62
63 Args:
64 error: The exception that was raised
65
66 Returns:
67 Exit code to return from the command
68 """
69 # Log the full error for debugging
70 logger.debug(f"Error details: {error}", exc_info=True)
71
72 # Handle credential errors
73 if isinstance(error, CredentialError):
74 # Extract error type from the message
75 if "AWS" in str(error):
76 error_type = "AWS credentials error"
77 elif "GitHub" in str(error):
78 error_type = "GitHub credentials error"
79 else:
80 error_type = "Credential error"
81 print_error(error_type, f"Error: {error}", getattr(error, 'suggestion', None))
82 return 1
83
84 # Handle GitHub errors
85 elif isinstance(error, GitHubError):
86 if isinstance(error, AuthenticationError):
87 print_error(
88 "GitHub authentication failed",
89 f"Error: {error}",
90 "Check your GitHub token or set the GITHUB_TOKEN environment variable."
91 )
92 elif "Organization is required" in str(error):
93 print_error(
94 "GitHub organization or user required",
95 f"Error: {error}",
96 "Specify an organization with --org or a user with --user."
97 )
98 elif "Repository owner is required" in str(error):
99 print_error(
100 "Repository owner required",
101 f"Error: {error}",
102 "Specify the repository owner with --owner or use the full repository path (owner/repo)."
103 )
104 else:
105 print_error(f"GitHub error", f"Error: {error}")
106 return 1
107 # Handle AWS service errors
108 elif isinstance(error, AWSServiceError):
109 error_type = error.__class__.__name__
110 print_error(f"AWS operation failed: {error_type}", f"Error: {error}", getattr(error, 'suggestion', None))
111 return 1
112
113 # Handle other errors
114 else:
115 print_error(f"Unexpected error", f"Error: {error}")
116 return 1

Callers 3

handle_ec2_commandFunction · 0.70
handle_github_commandFunction · 0.70
handle_deploy_commandFunction · 0.70

Calls 1

print_errorFunction · 0.70

Tested by

no test coverage detected