MCPcopy
hub / github.com/coder/mux / mapNameGenerationError

Function mapNameGenerationError

src/node/services/workspaceTitleGenerator.ts:48–98  ·  view source on GitHub ↗
(error: unknown, modelString: string)

Source from the content-addressed store, hash-verified

46}
47
48export function mapNameGenerationError(error: unknown, modelString: string): NameGenerationError {
49 if (RetryError.isInstance(error) && error.lastError) {
50 return mapNameGenerationError(error.lastError, modelString);
51 }
52
53 const provider = inferProviderFromModelString(modelString);
54
55 if (APICallError.isInstance(error)) {
56 if (error.statusCode === 401) {
57 return {
58 type: "authentication",
59 authKind: "invalid_credentials",
60 provider,
61 raw: error.message,
62 };
63 }
64 if (error.statusCode === 403) {
65 return { type: "permission_denied", provider, raw: error.message };
66 }
67 if (error.statusCode === 402) {
68 return { type: "quota", raw: error.message };
69 }
70 if (error.statusCode === 429) {
71 const kind = classify429Capacity({
72 message: error.message,
73 data: error.data,
74 responseBody: error.responseBody,
75 });
76 return { type: kind, raw: error.message };
77 }
78 if (error.statusCode != null && error.statusCode >= 500) {
79 return { type: "service_unavailable", raw: error.message };
80 }
81 }
82
83 // NoOutputGeneratedError can still occur with tool-based generation when a
84 // provider returns no output at all (e.g. empty response before any tool call).
85 if (NoOutputGeneratedError.isInstance(error)) {
86 return {
87 type: "unknown",
88 raw: "No output generated from the AI provider.",
89 };
90 }
91
92 if (error instanceof TypeError && error.message.toLowerCase().includes("fetch")) {
93 return { type: "network", raw: error.message };
94 }
95
96 const raw = getErrorMessage(error);
97 return { type: "unknown", raw };
98}
99
100export function mapModelCreationError(
101 error: SendMessageError,

Callers 4

generateWorkspaceStatusFunction · 0.90
askSideQuestionFunction · 0.90

Calls 3

classify429CapacityFunction · 0.90
getErrorMessageFunction · 0.90

Tested by

no test coverage detected