{"record":{"id":"98dddbec17b44b72","repo":"Budibase/budibase","slug":"failuremessage","errorCode":null,"errorMessage":"${failureMessage}","messagePattern":"\\$\\{failureMessage\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/server/src/ai/tools/index.ts","lineNumber":133,"sourceCode":"      }\n      await runtime.authorize({\n        authorization: toolDef.authorization,\n        input,\n        executionContext: runtime.executionContext,\n        principal: runtime.principal,\n      })\n    }\n    if (gate) {\n      return await gate.intercept(input, {\n        toolCallId: options?.toolCallId ?? \"\",\n        messages: options?.messages,\n      })\n    }\n    try {\n      const result = await execute(input, options)\n      const failureMessage = getToolFailure(result)\n      if (failureMessage) {\n        throw new Error(failureMessage)\n      }\n      const authorizedResult =\n        runtime && toolDef.filterResult\n          ? await toolDef.filterResult(result, runtime)\n          : result\n      if (runtime) {\n        logToolExecution(\"success\", toolDef, runtime)\n      }\n      return authorizedResult\n    } catch (error) {\n      if (runtime) {\n        logToolExecution(\"error\", toolDef, runtime)\n      }\n      throw error\n    }\n  }\n\n  return {","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/ai/tools/index.ts#L115-L151","documentation":"The tool's execute returned a result flagged as a failure by getToolFailure; wrappedExecute converts that into a thrown Error carrying the failure message. It surfaces tool-level logical failures (as opposed to exceptions) so the calling agent sees them as errors.","triggerScenarios":"A tool's execute() returns a result object whose failure field/message is populated, e.g. an upstream API error captured into the result rather than thrown.","commonSituations":"Query tool calls a REST query that returns an error status; search tool gets an API error and encodes it in the result; tool implementation sets failureMessage on partial failure.","solutions":["Fix the underlying tool failure indicated by the message (inspect the message text for the real cause)","Check the upstream query/API the tool invokes and ensure credentials/parameters are valid","Handle the thrown error in the agent loop and retry with corrected input"],"exampleFix":"// before\nconst result = await tool.execute(input) // result carries failure, thrown here\n// after\ntry {\n  await tool.execute(input)\n} catch (e) {\n  // inspect e.message from getToolFailure to find the root cause\n}","handlingStrategy":"try-catch","validationCode":"const result = await execute(input, options); const failure = getToolFailure(result); if (failure) { /* handle before it becomes a throw */ }","typeGuard":null,"tryCatchPattern":"try { await tool.run(input) } catch (e) { log.error(\"tool failure:\", e.message); /* retry or surface to agent */ }","preventionTips":["Handle failure-flagged results in custom tool implementations","Validate tool inputs before execution to reduce upstream failures","Monitor tool failure messages for recurring upstream API issues"],"tags":["ai","tools","error-propagation"],"backgroundTag":"tool-execution-failed","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}