{"record":{"id":"6f5d082484ada971","repo":"jd-opensource/joyagent-jdgenie","slug":"tool-execution-failed-error","errorCode":null,"errorMessage":"Tool execution failed: \" + error","messagePattern":"Tool execution failed: \" \\+ error","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"genie-backend/src/main/java/com/jd/genie/agent/dto/tool/ToolResult.java","lineNumber":154,"sourceCode":"     * 检查是否被取消\n     */\n    public boolean isCancelled() {\n        return status == ExecutionStatus.CANCELLED;\n    }\n\n    /**\n     * 检查是否被跳过\n     */\n    public boolean isSkipped() {\n        return status == ExecutionStatus.SKIPPED;\n    }\n\n    /**\n     * 获取结果或抛出异常\n     */\n    public <T> T getResultOrThrow(Class<T> resultType) {\n        if (!isSuccess()) {\n            throw new IllegalStateException(\"Tool execution failed: \" + error);\n        }\n\n        if (result == null) {\n            throw new IllegalStateException(\"Tool execution result is null\");\n        }\n\n        if (!resultType.isInstance(result)) {\n            throw new ClassCastException(\"Result is not of type \" + resultType.getName());\n        }\n\n        return resultType.cast(result);\n    }\n\n    /**\n     * 获取结果或返回默认值\n     */\n    public <T> T getResultOrDefault(Class<T> resultType, T defaultValue) {\n        try {","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-backend/src/main/java/com/jd/genie/agent/dto/tool/ToolResult.java#L136-L172","documentation":"ToolResult.getResultOrThrow throws IllegalStateException when the tool execution completed but isSuccess() is false, meaning the tool reported a failure via its error field. The message embeds the underlying tool error string so callers can see why the tool failed.","triggerScenarios":"Calling getResultOrThrow/getResultOrDefault on a ToolResult where the execution failed and the error field is non-null.","commonSituations":"Tool execution threw internally, the tool returned an error response from an external API, or a timeout/parse failure set the error field before the agent reads the result.","solutions":["Check isSuccess() before calling getResultOrThrow and handle the failure path","Log ToolResult.getError() to find the root cause of the tool failure","Fix the underlying tool invocation that produced the error"],"exampleFix":"// before\nT result = toolResult.getResultOrThrow(MyResult.class);\n// after\nif (!toolResult.isSuccess()) {\n    log.warn(\"tool failed: {}\", toolResult.getError());\n    return fallbackResult();\n}\nT result = toolResult.getResultOrThrow(MyResult.class);","handlingStrategy":"try-catch","validationCode":"if (toolResult == null || !toolResult.isSuccess()) { /* take failure path */ }","typeGuard":"boolean usable(ToolResult r) { return r != null && r.isSuccess() && r.getResult() != null; }","tryCatchPattern":"try {\n    T r = toolResult.getResultOrThrow(T.class);\n} catch (IllegalStateException e) {\n    log.warn(\"tool failed: {}\", toolResult.getError());\n    return fallback;\n}","preventionTips":["Check isSuccess() before unwrapping","Always log getError() for diagnosis","Treat tool results as fallible and provide fallbacks"],"tags":["java","agent","tool-execution"],"backgroundTag":"invalid-state-transition","analyzedSha":"2417e0b8b636d941ad5fb14c59b20dddfef5375d","analyzedAt":"2026-09-08T11:28:19.414Z","contentChangedAt":"2026-09-08T11:28:19.414Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}