Repository navigation
Expand file tree
/
Copy patherrors.py
More file actions
122 lines (86 loc) · 3.17 KB
/
Copy patherrors.py
File metadata and controls
122 lines (86 loc) · 3.17 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""
Error handling utilities and exit codes for CLI.
Exit Codes:
0: Success
1: General error
2: Configuration error (missing/invalid credentials)
3: Repository error (not a git repo, no code files)
4: LLM API error (including rate limits)
5: File system error (permissions, disk space)
6: Incomplete generation (module docs missing; re-run to resume)
"""
import sys
import click
# Exit codes
EXIT_SUCCESS = 0
EXIT_GENERAL_ERROR = 1
EXIT_CONFIG_ERROR = 2
EXIT_REPOSITORY_ERROR = 3
EXIT_API_ERROR = 4
EXIT_FILESYSTEM_ERROR = 5
EXIT_INCOMPLETE_GENERATION = 6
class CodeWikiError(Exception):
"""Base exception for CodeWiki CLI errors."""
def __init__(self, message: str, exit_code: int = EXIT_GENERAL_ERROR):
self.message = message
self.exit_code = exit_code
super().__init__(self.message)
class ConfigurationError(CodeWikiError):
"""Configuration-related errors."""
def __init__(self, message: str):
super().__init__(message, EXIT_CONFIG_ERROR)
class RepositoryError(CodeWikiError):
"""Repository-related errors."""
def __init__(self, message: str):
super().__init__(message, EXIT_REPOSITORY_ERROR)
class APIError(CodeWikiError):
"""LLM API-related errors."""
def __init__(self, message: str):
super().__init__(message, EXIT_API_ERROR)
class FileSystemError(CodeWikiError):
"""File system-related errors."""
def __init__(self, message: str):
super().__init__(message, EXIT_FILESYSTEM_ERROR)
class IncompleteGenerationError(CodeWikiError):
"""Generation finished but some module docs are missing on disk."""
def __init__(self, message: str, missing_modules: list = None):
self.missing_modules = missing_modules or []
super().__init__(message, EXIT_INCOMPLETE_GENERATION)
def handle_error(error: Exception, verbose: bool = False) -> int:
"""
Handle errors and return appropriate exit code.
Args:
error: The exception to handle
verbose: Whether to show detailed error information
Returns:
Exit code for the error
"""
if isinstance(error, CodeWikiError):
click.secho(f"\n✗ Error: {error.message}", fg="red", err=True)
return error.exit_code
else:
click.secho(f"\n✗ Unexpected error: {error}", fg="red", err=True)
if verbose:
import traceback
click.echo(traceback.format_exc(), err=True)
return EXIT_GENERAL_ERROR
def error_with_suggestion(message: str, suggestion: str, exit_code: int = EXIT_GENERAL_ERROR):
"""
Display error message with actionable suggestion and exit.
Args:
message: The error message
suggestion: Suggested action to resolve the error
exit_code: Exit code to use
"""
click.secho(f"\n✗ Error: {message}", fg="red", err=True)
click.echo(f"\n{suggestion}", err=True)
sys.exit(exit_code)
def warning(message: str):
"""Display a warning message."""
click.secho(f"⚠️ {message}", fg="yellow")
def success(message: str):
"""Display a success message."""
click.secho(f"✓ {message}", fg="green")
def info(message: str):
"""Display an info message."""
click.echo(message)