{"record":{"id":"74e7d9f6ce9a76a5","repo":"gitbutlerapp/gitbutler","slug":"failed-to-parse-parameters-e","errorCode":null,"errorMessage":"Failed to parse parameters: {e}","messagePattern":"Failed to parse parameters: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-tools/src/tool.rs","lineNumber":43,"sourceCode":"impl<'a> WorkspaceToolset<'a> {\n    pub fn new(ctx: &'a mut Context) -> Self {\n        WorkspaceToolset {\n            ctx,\n            tools: BTreeMap::new(),\n            commit_mapping: HashMap::new(),\n        }\n    }\n\n    fn call_tool_inner(\n        &mut self,\n        name: &str,\n        parameters: &str,\n    ) -> anyhow::Result<serde_json::Value> {\n        let tool = self\n            .get(name)\n            .ok_or_else(|| anyhow::anyhow!(\"Tool '{name}' not found\"))?;\n        let params: serde_json::Value = serde_json::from_str(parameters)\n            .map_err(|e| anyhow::anyhow!(\"Failed to parse parameters: {e}\"))?;\n        tool.call(params, self.ctx, &mut self.commit_mapping)\n    }\n}\n\nimpl Toolset for WorkspaceToolset<'_> {\n    fn register_tool<T: Tool>(&mut self, tool: T) {\n        self.tools.insert(tool.name(), Arc::new(tool));\n    }\n\n    fn get(&self, name: &str) -> Option<Arc<dyn Tool>> {\n        self.tools.get(name).cloned()\n    }\n\n    fn list(&self) -> Vec<Arc<dyn Tool>> {\n        self.tools.values().cloned().collect()\n    }\n\n    fn call_tool(&mut self, name: &str, parameters: &str) -> serde_json::Value {","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-tools/src/tool.rs#L25-L61","documentation":"After locating the tool, `call_tool_inner` parses the `parameters` JSON string with serde_json::from_str; a malformed JSON string is wrapped in this error. It is a pre-call parameter decoding failure, not a tool execution failure.","triggerScenarios":"Passing a parameters string that is invalid JSON (truncated output from an LLM, unescaped newlines/quotes, trailing commas, or a non-JSON plain string).","commonSituations":"Model-generated tool arguments arrive with prose or markdown around the JSON; streaming responses cut mid-JSON; hand-written automation passes single-quoted (Python-style) JSON.","solutions":["Validate/repair the parameters string with JSON.parse or serde_json::from_str on the caller side before invoking","Strip markdown fences/prose and re-extract the JSON object from the LLM output","Ensure streamed tool-call arguments are fully accumulated before parsing","Log the raw parameters string to spot the exact syntax problem"],"exampleFix":"// before\ntoolset.call_tool(\"commit\", \"{'message': 'hi'}\")?; // invalid JSON\n// after\ntoolset.call_tool(\"commit\", r#\"{\"message\": \"hi\"}\"#)?;","handlingStrategy":"validation","validationCode":"function safeParams(raw: string): string {\n  JSON.parse(raw); // throws before the call if invalid\n  return raw;\n}\ntoolset.call_tool(name, safeParams(raw));","typeGuard":"function isValidJson(s: string): boolean {\n  try { JSON.parse(s); return true; } catch { return false; }\n}","tryCatchPattern":"try {\n  toolset.call_tool(name, params_str)\n} catch (e) {\n  if (String(e).startsWith('Failed to parse parameters')) {\n    const repaired = extractJsonObject(params_str);\n    return repaired ? toolset.call_tool(name, repaired) : Err(e);\n  }\n  throw e;\n}","preventionTips":["Always build parameters with JSON.stringify, not string concatenation","Fully accumulate streamed LLM tool-call arguments before parsing","Strip code fences/prose from model output","Unit-test tool invocation with realistic model outputs"],"tags":["json","parsing","tools","parameters"],"backgroundTag":"json-parse-error","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}