Problem
The plugin system has hooks for tool.execute.before and tool.execute.after, allowing plugins to intercept and modify tool inputs/outputs. However, there's no way to hook into tool errors.
When a tool throws an error, plugins cannot:
- Log or track the error
- Modify the error message to be more helpful
- Recover from known errors by returning a fallback result
Use Case
Sometimes you know exactly what an error means and want to handle it gracefully. For example:
- A file read fails because the file doesn't exist - you might want to return a friendly message instead of a stack trace
- An API call hits a rate limit - you might want to modify the error to suggest waiting
- A known transient error occurs - you might want to return a cached/fallback result
Proposed Solution
Add a tool.execute.error hook that fires when tool execution throws:
"tool.execute.error"?: (
input: { tool: string; sessionID: string; callID: string; args: any },
output: {
error: Error
result?: { title: string; output: string; metadata: any }
},
) => Promise<void>
Plugins could either:
- Modify
output.error to change the error that gets thrown
- Set
output.result to return a successful result instead of throwing
Example Usage
export default {
hooks: {
"tool.execute.error": async (input, output) => {
console.error(`Tool ${input.tool} failed:`, output.error.message)
// Option 1: Modify error message
if (output.error.message.includes("rate limit")) {
output.error = new Error("Service temporarily unavailable, please try again")
}
// Option 2: Recover from error by providing a result
if (input.tool === "read" && output.error.message.includes("not found")) {
output.result = {
title: "File not found",
output: `The file ${input.args.filePath} does not exist.`,
metadata: {}
}
}
}
}
}
Problem
The plugin system has hooks for
tool.execute.beforeandtool.execute.after, allowing plugins to intercept and modify tool inputs/outputs. However, there's no way to hook into tool errors.When a tool throws an error, plugins cannot:
Use Case
Sometimes you know exactly what an error means and want to handle it gracefully. For example:
Proposed Solution
Add a
tool.execute.errorhook that fires when tool execution throws:Plugins could either:
output.errorto change the error that gets thrownoutput.resultto return a successful result instead of throwingExample Usage