-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy patherrors.ts
More file actions
207 lines (185 loc) · 6.19 KB
/
Copy patherrors.ts
File metadata and controls
207 lines (185 loc) · 6.19 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/**
* Typed error hierarchy for the orchestrator.
*
* Every error carries an exit code (matching CLI_UI_DESIGN.md §11)
* and an optional hint for the user.
*
* Exit codes:
* 0 - Success
* 1 - General error
* 2 - Invalid arguments
* 3 - Not initialized (.orchestry/ not found)
* 4 - Lock conflict (orchestrator already running)
* 5 - Agent error (adapter test failed)
*/
export class OrchestryError extends Error {
constructor(
message: string,
public readonly exitCode: number,
public readonly hint?: string,
) {
super(message);
this.name = 'OrchestryError';
}
}
export class NotInitializedError extends OrchestryError {
constructor() {
super('Not initialized', 3, 'Run: orch init');
this.name = 'NotInitializedError';
}
}
export class InvalidArgumentsError extends OrchestryError {
constructor(message: string) {
super(message, 2);
this.name = 'InvalidArgumentsError';
}
}
export class LockConflictError extends OrchestryError {
constructor(pid: number) {
super(`Orchestrator already running (PID: ${pid})`, 4, 'Use: orch status');
this.name = 'LockConflictError';
}
}
export class AgentAdapterError extends OrchestryError {
constructor(adapter: string, detail: string) {
super(`Agent adapter "${adapter}" not available`, 5, detail);
this.name = 'AgentAdapterError';
}
}
export class NoAgentsError extends OrchestryError {
constructor() {
super('No agents configured', 1, 'Run: orch agent add <name> --adapter <adapter>');
this.name = 'NoAgentsError';
}
}
export class TaskNotFoundError extends OrchestryError {
constructor(taskId: string) {
super(`Task not found: ${taskId}`, 1);
this.name = 'TaskNotFoundError';
}
}
export class AgentNotFoundError extends OrchestryError {
constructor(agentId: string) {
super(`Agent not found: ${agentId}`, 1);
this.name = 'AgentNotFoundError';
}
}
export class TaskAlreadyRunningError extends OrchestryError {
constructor(taskId: string, runId: string, agentName: string) {
super(
`Task ${taskId} is already running (run: ${runId}, agent: ${agentName})`,
1,
`Use: orch logs --task ${taskId} --follow`,
);
this.name = 'TaskAlreadyRunningError';
}
}
export class InvalidTransitionError extends OrchestryError {
constructor(taskId: string, from: string, to: string) {
super(`Invalid transition for ${taskId}: ${from} → ${to}`, 1);
this.name = 'InvalidTransitionError';
}
}
export class GoalNotFoundError extends OrchestryError {
constructor(goalId: string) {
super(`Goal not found: ${goalId}`, 1);
this.name = 'GoalNotFoundError';
}
}
export class GoalHasPendingTasksError extends OrchestryError {
constructor(goalId: string, count: number, summary: string) {
super(
`Cannot mark goal ${goalId} as achieved: ${count} task(s) still pending — ${summary}`,
1,
'Use --force to cancel pending tasks and mark achieved',
);
this.name = 'GoalHasPendingTasksError';
}
}
export class TeamNotFoundError extends OrchestryError {
constructor(teamId: string) {
super(`Team not found: ${teamId}`, 1);
this.name = 'TeamNotFoundError';
}
}
export class MessageNotFoundError extends OrchestryError {
constructor(messageId: string) {
super(`Message not found: ${messageId}`, 1);
this.name = 'MessageNotFoundError';
}
}
export class WorkspaceError extends OrchestryError {
constructor(message: string, hint?: string) {
super(message, 6, hint);
this.name = 'WorkspaceError';
}
}
// ── Adapter Error Classification ──────────────────────────────────
export enum AdapterErrorKind {
ADAPTER_NOT_FOUND = 'adapter_not_found',
AUTH_FAILED = 'auth_failed',
TIMEOUT = 'timeout',
RATE_LIMIT = 'rate_limit',
PROCESS_CRASH = 'process_crash',
SPAWN_FAILED = 'spawn_failed',
UNKNOWN = 'unknown',
}
export interface AdapterErrorHint {
message: string;
fix: string;
doctorHint?: boolean;
}
export const ERROR_HINTS: Record<AdapterErrorKind, AdapterErrorHint> = {
[AdapterErrorKind.ADAPTER_NOT_FOUND]: {
message: 'CLI не установлен.',
fix: 'Установите: npm i -g @anthropic-ai/claude-code',
doctorHint: true,
},
[AdapterErrorKind.AUTH_FAILED]: {
message: 'API ключ невалиден.',
fix: 'Проверьте: claude auth status',
},
[AdapterErrorKind.TIMEOUT]: {
message: 'Агент превысил лимит времени.',
fix: 'Увеличьте через: orch config set agent_timeout <ms>',
},
[AdapterErrorKind.RATE_LIMIT]: {
message: 'Достигнут лимит API.',
fix: 'Подождите и повторите: orch task retry <id>',
},
[AdapterErrorKind.PROCESS_CRASH]: {
message: 'Процесс агента упал.',
fix: 'Попробуйте: orch task retry <id>',
},
[AdapterErrorKind.SPAWN_FAILED]: {
message: 'Не удалось запустить процесс.',
fix: 'Проверьте PATH и права доступа',
},
[AdapterErrorKind.UNKNOWN]: {
message: 'Неизвестная ошибка.',
fix: 'Запустите: orch doctor',
doctorHint: true,
},
};
export function classifyAdapterError(error: string, exitCode?: number): AdapterErrorKind {
const lower = error.toLowerCase();
if (lower.includes('enoent') || lower.includes('spawn failed')) {
return AdapterErrorKind.SPAWN_FAILED;
}
if (lower.includes('not found') || lower.includes('command not found') || lower.includes('no such file')) {
return AdapterErrorKind.ADAPTER_NOT_FOUND;
}
if (lower.includes('auth') || lower.includes('unauthorized') || lower.includes('401') || lower.includes('invalid api key') || lower.includes('authentication')) {
return AdapterErrorKind.AUTH_FAILED;
}
if (lower.includes('timeout') || lower.includes('timed out') || lower.includes('etimedout')) {
return AdapterErrorKind.TIMEOUT;
}
if (lower.includes('rate limit') || lower.includes('429') || lower.includes('too many requests')) {
return AdapterErrorKind.RATE_LIMIT;
}
if (exitCode !== undefined && exitCode !== 0) {
return AdapterErrorKind.PROCESS_CRASH;
}
return AdapterErrorKind.UNKNOWN;
}