MCPcopy
hub / github.com/continuedev/continue / formatError

Function formatError

extensions/cli/src/util/formatError.ts:4–53  ·  view source on GitHub ↗
(error: any)

Source from the content-addressed store, hash-verified

2 * Safely formats an error object into a readable string
3 */
4export function formatError(error: any): string {
5 if (error instanceof Error) {
6 return error.message;
7 }
8
9 if (typeof error === "string") {
10 return error;
11 }
12
13 if (error && typeof error === "object") {
14 // Try to extract common error properties
15 if (error.message) {
16 return error.message;
17 }
18 if (error.error) {
19 return formatError(error.error);
20 }
21 if (error.details) {
22 return formatError(error.details);
23 }
24 if (error.description) {
25 return error.description;
26 }
27
28 // For API errors, try to extract meaningful info
29 if (error.status && error.error && error.error.message) {
30 return `HTTP ${error.status}: ${error.error.message}`;
31 }
32
33 // For network errors
34 if (error.code && error.syscall) {
35 return `Network error: ${error.code} in ${error.syscall}`;
36 }
37
38 // For errors with an errors array
39 if (error.errors && Array.isArray(error.errors)) {
40 return error.errors.join(", ");
41 }
42
43 // Try to JSON stringify if possible
44 try {
45 return JSON.stringify(error);
46 } catch {
47 // If JSON.stringify fails, return a generic message
48 return `An error occurred: ${Object.prototype.toString.call(error)}`;
49 }
50 }
51
52 return String(error);
53}
54
55// Anthropic errors are stringfied JSON objects, format them to be more user friendly
56export function formatAnthropicError(error: any): string {

Callers 15

syncSessionHistoryFunction · 0.85
serveFunction · 0.85
handleExitResponseFunction · 0.85
processMessagesFunction · 0.85
handleManualCompactionFunction · 0.85
processMessageFunction · 0.85
chatFunction · 0.85
findEnvironmentFileFunction · 0.85
runEnvironmentInstallFunction · 0.85
startMethod · 0.85
markAgentStatusUnreadMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected