_errors.js
1001 Bytes
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
/**
* DevLoop tool layer · 标准化错误类型
*
* 用法:
* throw new ToolValidationError('summary', 'too short');
* throw new ToolSandboxError('/abs/path', 'pm');
*
* Claude CLI 看到 thrown error → 包装为 tool_result { is_error: true, content: msg }
*/
class ToolValidationError extends Error {
constructor(field, reason) {
super(`${field}: ${reason}`);
this.name = 'ToolValidationError';
this.field = field;
this.reason = reason;
}
}
class ToolSandboxError extends Error {
constructor(p, agent) {
super(`Sandbox violation: ${agent} tried to write ${p}`);
this.name = 'ToolSandboxError';
this.path = p;
this.agent = agent;
}
}
class ToolMissingDependencyError extends Error {
constructor(dep) {
super(`Tool requires ${dep} in ctx (LoopController injection)`);
this.name = 'ToolMissingDependencyError';
this.dep = dep;
}
}
module.exports = {
ToolValidationError,
ToolSandboxError,
ToolMissingDependencyError,
};