-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy paththreadError.ts
More file actions
56 lines (48 loc) · 1.58 KB
/
threadError.ts
File metadata and controls
56 lines (48 loc) · 1.58 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
import { redactSensitiveText } from "@okcode/shared/redaction";
export interface ThreadErrorPresentation {
title: string | null;
description: string;
technicalDetails: string | null;
}
const WORKTREE_COMMAND_PREFIX = "Git command failed in GitCore.createWorktree:";
const AUTH_FAILURE_PATTERNS = [
"run `codex login`",
"run codex login",
"run `claude auth login`",
"run claude auth login",
"codex cli is not authenticated",
"claude is not authenticated",
"authentication required",
] as const;
function extractWorktreeDetail(error: string): string | null {
if (!error.startsWith(WORKTREE_COMMAND_PREFIX)) {
return null;
}
const separatorIndex = error.lastIndexOf(" - ");
const detail = separatorIndex >= 0 ? error.slice(separatorIndex + 3).trim() : error.trim();
return detail.length > 0 ? detail : null;
}
export function isAuthenticationThreadError(error: string | null | undefined): boolean {
const trimmed = error?.trim();
if (!trimmed) {
return false;
}
const lower = trimmed.toLowerCase();
return AUTH_FAILURE_PATTERNS.some((pattern) => lower.includes(pattern));
}
export function humanizeThreadError(error: string): ThreadErrorPresentation {
const trimmed = redactSensitiveText(error).trim();
const worktreeDetail = extractWorktreeDetail(trimmed);
if (worktreeDetail) {
return {
title: "Worktree thread could not start",
description: worktreeDetail,
technicalDetails: trimmed,
};
}
return {
title: null,
description: trimmed.length > 0 ? trimmed : "An unexpected error occurred.",
technicalDetails: null,
};
}