Skip to content

Commit d1d1df7

Browse files
author
linyuan.yang
committed
formatError
1 parent 38776a8 commit d1d1df7

20 files changed

Lines changed: 59 additions & 63 deletions

File tree

‎packages/sbot/src/Tools/Archive/compress.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import AdmZip from 'adm-zip';
44
import { DynamicStructuredTool, type StructuredToolInterface } from '@langchain/core/tools';
55
import { z } from 'zod';
66
import { LoggerService } from '../../Core/LoggerService';
7-
import { createTextContent, createErrorResult, createSuccessResult, type MCPToolResult } from 'scorpio.ai';
7+
import { createTextContent, createErrorResult, createSuccessResult, formatError, type MCPToolResult } from 'scorpio.ai';
88
import { resolvePath, formatSize } from '../FileSystem/utils';
99
import { loadPrompt } from '../../Core/PromptLoader';
1010

@@ -53,8 +53,8 @@ export function createZipCompressTool(): StructuredToolInterface {
5353
createTextContent(`Created: ${destAbs} (${formatSize(size)}, ${entryCount} entries)`),
5454
);
5555
} catch (e: any) {
56-
logger.error(`zip_compress: ${e.message}`);
57-
return createErrorResult(e.message);
56+
logger.error(`zip_compress: ${formatError(e, true)}`);
57+
return createErrorResult(formatError(e));
5858
}
5959
},
6060
});

‎packages/sbot/src/Tools/Archive/extract.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import AdmZip from 'adm-zip';
33
import { DynamicStructuredTool, type StructuredToolInterface } from '@langchain/core/tools';
44
import { z } from 'zod';
55
import { LoggerService } from '../../Core/LoggerService';
6-
import { createTextContent, createErrorResult, createSuccessResult, type MCPToolResult } from 'scorpio.ai';
6+
import { createTextContent, createErrorResult, createSuccessResult, formatError, type MCPToolResult } from 'scorpio.ai';
77
import { resolvePath } from '../FileSystem/utils';
88
import { loadPrompt } from '../../Core/PromptLoader';
99

@@ -38,8 +38,8 @@ export function createZipExtractTool(): StructuredToolInterface {
3838
createTextContent(`Extracted to: ${outAbs} (${dirCount} directories, ${fileCount} files)`),
3939
);
4040
} catch (e: any) {
41-
logger.error(`zip_extract: ${e.message}`);
42-
return createErrorResult(e.message);
41+
logger.error(`zip_extract: ${formatError(e, true)}`);
42+
return createErrorResult(formatError(e));
4343
}
4444
},
4545
});

‎packages/sbot/src/Tools/Archive/list.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import AdmZip from 'adm-zip';
33
import { DynamicStructuredTool, type StructuredToolInterface } from '@langchain/core/tools';
44
import { z } from 'zod';
55
import { LoggerService } from '../../Core/LoggerService';
6-
import { createTextContent, createErrorResult, createSuccessResult, type MCPToolResult } from 'scorpio.ai';
6+
import { createTextContent, createErrorResult, createSuccessResult, formatError, type MCPToolResult } from 'scorpio.ai';
77
import { resolvePath, formatSize } from '../FileSystem/utils';
88
import { loadPrompt } from '../../Core/PromptLoader';
99

@@ -40,8 +40,8 @@ export function createZipListTool(): StructuredToolInterface {
4040
createTextContent(`${lines.join('\n')}\n\n${summary}`),
4141
);
4242
} catch (e: any) {
43-
logger.error(`zip_list: ${e.message}`);
44-
return createErrorResult(e.message);
43+
logger.error(`zip_list: ${formatError(e, true)}`);
44+
return createErrorResult(formatError(e));
4545
}
4646
},
4747
});

‎packages/sbot/src/Tools/Archive/read.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import AdmZip from 'adm-zip';
33
import { DynamicStructuredTool, type StructuredToolInterface } from '@langchain/core/tools';
44
import { z } from 'zod';
55
import { LoggerService } from '../../Core/LoggerService';
6-
import { createTextContent, createErrorResult, createSuccessResult, type MCPToolResult } from 'scorpio.ai';
6+
import { createTextContent, createErrorResult, createSuccessResult, formatError, type MCPToolResult } from 'scorpio.ai';
77
import { resolvePath } from '../FileSystem/utils';
88
import { loadPrompt } from '../../Core/PromptLoader';
99

@@ -45,8 +45,8 @@ export function createZipReadFileTool(): StructuredToolInterface {
4545
logger.info(`zip_read_file: ${zipAbs}!${entryPath}`);
4646
return createSuccessResult(createTextContent(buf.toString('utf-8')));
4747
} catch (e: any) {
48-
logger.error(`zip_read_file: ${e.message}`);
49-
return createErrorResult(e.message);
48+
logger.error(`zip_read_file: ${formatError(e, true)}`);
49+
return createErrorResult(formatError(e));
5050
}
5151
},
5252
});

‎packages/sbot/src/Tools/Channel/list.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DynamicStructuredTool, type StructuredToolInterface } from '@langchain/core/tools';
22
import { z } from 'zod';
3-
import { createTextContent, createErrorResult, createSuccessResult, type MCPToolResult } from 'scorpio.ai';
3+
import { createTextContent, createErrorResult, createSuccessResult, formatError, type MCPToolResult } from 'scorpio.ai';
44
import { WEB_CHANNEL_TYPE } from 'sbot.commons';
55
import { channelDataService, type ChannelSessionWithProfile } from '../../Session/ChannelDataService';
66
import { channelManager } from '../../Channel/ChannelManager';
@@ -73,8 +73,8 @@ export function createChannelListTool(currentChannelId?: string): StructuredTool
7373
`<channels count="${channels.length}">\n${channelBlocks.join('\n')}\n</channels>`
7474
));
7575
} catch (e: any) {
76-
logger.error(`${CHANNEL_LIST_TOOL_NAME} failed: ${e.message}`);
77-
return createErrorResult(`Failed to list: ${e.message}`);
76+
logger.error(`${CHANNEL_LIST_TOOL_NAME} failed: ${formatError(e, true)}`);
77+
return createErrorResult(`Failed to list: ${formatError(e)}`);
7878
}
7979
},
8080
});

‎packages/sbot/src/Tools/Channel/send.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'path';
22
import { DynamicStructuredTool, type StructuredToolInterface } from '@langchain/core/tools';
33
import { z } from 'zod';
4-
import { createTextContent, createErrorResult, createSuccessResult, type MCPToolResult } from 'scorpio.ai';
4+
import { createTextContent, createErrorResult, createSuccessResult, formatError, type MCPToolResult } from 'scorpio.ai';
55
import { channelManager } from '../../Channel/ChannelManager';
66
import { LoggerService } from '../../Core/LoggerService';
77
import { loadPrompt } from '../../Core/PromptLoader';
@@ -50,8 +50,8 @@ export function createChannelSendTool(): StructuredToolInterface {
5050
}
5151
return createSuccessResult(createTextContent('ok'));
5252
} catch (e: any) {
53-
logger.error(`${CHANNEL_SEND_TOOL_NAME} failed: ${e.message}`);
54-
return createErrorResult(`Send failed: ${e.message}`);
53+
logger.error(`${CHANNEL_SEND_TOOL_NAME} failed: ${formatError(e, true)}`);
54+
return createErrorResult(`Send failed: ${formatError(e)}`);
5555
}
5656
},
5757
});

‎packages/sbot/src/Tools/FileSystem/content/edit.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createTwoFilesPatch } from 'diff';
33
import { DynamicStructuredTool, type StructuredToolInterface } from '@langchain/core/tools';
44
import { z } from 'zod';
55
import { LoggerService } from '../../../Core/LoggerService';
6-
import { createTextContent, createErrorResult, createSuccessResult, MCPToolResult } from 'scorpio.ai';
6+
import { createTextContent, createErrorResult, createSuccessResult, formatError, MCPToolResult } from 'scorpio.ai';
77
import { checkFile, normalizeLineEndings, writeAtomic } from '../utils';
88
import { loadPrompt } from '../../../Core/PromptLoader';
99

@@ -332,8 +332,8 @@ export function createEditFileTool(): StructuredToolInterface {
332332
}
333333
return createSuccessResult(createTextContent(diffs.join('')));
334334
} catch (e: any) {
335-
logger.error(`edit_file: ${e.message}`);
336-
return createErrorResult(e.message);
335+
logger.error(`edit_file: ${formatError(e, true)}`);
336+
return createErrorResult(formatError(e));
337337
}
338338
}
339339
});

‎packages/sbot/src/Tools/FileSystem/content/grep.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { spawn } from 'child_process';
55
import { DynamicStructuredTool, type StructuredToolInterface } from '@langchain/core/tools';
66
import { z } from 'zod';
77
import { LoggerService } from '../../../Core/LoggerService';
8-
import { createTextContent, createErrorResult, createSuccessResult, MCPToolResult } from 'scorpio.ai';
8+
import { createTextContent, createErrorResult, createSuccessResult, formatError, MCPToolResult } from 'scorpio.ai';
99
import { checkDir, globToRegex, EXCLUDE_DIRS, checkRg } from '../utils';
1010
import { loadPrompt } from '../../../Core/PromptLoader';
1111

@@ -144,7 +144,7 @@ async function searchWithNodeJs(
144144
if (expired()) return;
145145
let entries;
146146
try { entries = await fsAsync.readdir(d, { withFileTypes: true }); }
147-
catch (e: any) { logger.warn(`Cannot access ${d}: ${e.message}`); return; }
147+
catch (e: any) { logger.warn(`Cannot access ${d}: ${formatError(e)}`); return; }
148148
for (const entry of entries) {
149149
if (expired()) return;
150150
if (!includeHidden && entry.name.startsWith('.')) continue;
@@ -245,8 +245,8 @@ export function createGrepFilesTool(): StructuredToolInterface {
245245
if (result.results.length === 0) return createSuccessResult(createTextContent('No matches found'));
246246
return createSuccessResult(createTextContent(formatResults(result.results, result.reachedLimit, maxMatches)));
247247
} catch (e: any) {
248-
logger.error(`grep_files ${searchPath}: ${e.message}`);
249-
return createErrorResult(e.message);
248+
logger.error(`grep_files ${searchPath}: ${formatError(e, true)}`);
249+
return createErrorResult(formatError(e));
250250
}
251251
}
252252
});

‎packages/sbot/src/Tools/FileSystem/content/read.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path from 'path';
44
import { DynamicStructuredTool, type StructuredToolInterface } from '@langchain/core/tools';
55
import { z } from 'zod';
66
import { LoggerService } from '../../../Core/LoggerService';
7-
import { createTextContent, createErrorResult, createSuccessResult, MCPToolResult } from 'scorpio.ai';
7+
import { createTextContent, createErrorResult, createSuccessResult, formatError, MCPToolResult } from 'scorpio.ai';
88
import { resolvePath } from '../utils';
99
import { loadPrompt } from '../../../Core/PromptLoader';
1010

@@ -204,8 +204,8 @@ export function createReadTool(): StructuredToolInterface {
204204
}
205205
return readLines(lines, from, stopAt);
206206
} catch (e: any) {
207-
logger.error(`read ${filePath}: ${e.message}`);
208-
return createErrorResult(e.message);
207+
logger.error(`read ${filePath}: ${formatError(e, true)}`);
208+
return createErrorResult(formatError(e));
209209
}
210210
}
211211
});

‎packages/sbot/src/Tools/FileSystem/content/readMediaFile.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { z } from 'zod';
55
import { LoggerService } from '../../../Core/LoggerService';
66
import {
77
createTextContent, createImageContent, createAudioContent, createDocumentContent,
8-
createErrorResult, createSuccessResult, detectImageMimeType, type MCPToolResult,
8+
createErrorResult, createSuccessResult, detectImageMimeType, formatError, type MCPToolResult,
99
} from 'scorpio.ai';
1010
import { checkFile, formatSize } from '../utils';
1111
import { loadPrompt } from '../../../Core/PromptLoader';
@@ -84,8 +84,8 @@ export function createReadMediaFileTool(): StructuredToolInterface {
8484
);
8585
}
8686
} catch (e: any) {
87-
logger.error(`read_media_file ${filePath}: ${e.message}`);
88-
return createErrorResult(e.message);
87+
logger.error(`read_media_file ${filePath}: ${formatError(e, true)}`);
88+
return createErrorResult(formatError(e));
8989
}
9090
},
9191
});

0 commit comments

Comments
 (0)