{"record":{"id":"6e090a76a06b2142","repo":"amir20/dozzle","slug":"failed-to-parse-arguments-w-6e090a","errorCode":null,"errorMessage":"failed to parse arguments: %w","messagePattern":"failed to parse arguments: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloud/tools_stream.go","lineNumber":22,"sourceCode":"\t\"context\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"regexp\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/amir20/dozzle/internal/container\"\n\tpb \"github.com/amir20/dozzle/proto/cloud\"\n\t\"github.com/rs/zerolog/log\"\n)\n\n// streamSender is a function that sends a ToolResponse to the cloud.\ntype streamSender func(resp *pb.ToolResponse) error\n\nfunc parseStreamArgs(argsJSON string) (*fetchLogsArgs, *regexp.Regexp, error) {\n\tvar args fetchLogsArgs\n\tif err := json.Unmarshal([]byte(argsJSON), &args); err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"failed to parse arguments: %w\", err)\n\t}\n\tif args.ContainerID == \"\" {\n\t\treturn nil, nil, fmt.Errorf(\"container_id is required\")\n\t}\n\n\tvar re *regexp.Regexp\n\tif args.Regex != \"\" {\n\t\tvar err error\n\t\tre, err = regexp.Compile(args.Regex)\n\t\tif err != nil {\n\t\t\treturn nil, nil, fmt.Errorf(\"invalid regex pattern: %w\", err)\n\t\t}\n\t}\n\treturn &args, re, nil\n}\n\nfunc matchesFilters(event *container.LogEvent, args *fetchLogsArgs, re *regexp.Regexp) (string, bool) {\n\tif args.Level != \"\" && !strings.EqualFold(event.Level, args.Level) {","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/amir20/dozzle/blob/d9463cbe21874e44ab79db6fa63e746ca7d22928/internal/cloud/tools_stream.go#L4-L40","documentation":"parseStreamArgs unmarshals the raw JSON arguments of a stream_logs tool call; when json.Unmarshal fails the JSON is wrapped as 'failed to parse arguments'. The cloud tool caller sent a body that is not valid JSON or has wrong types for fetchLogsArgs fields.","triggerScenarios":"executeStreamLogs receives argsJSON that json.Unmarshal rejects: malformed JSON syntax, non-string values for string fields, or a non-object payload.","commonSituations":"LLM emitting truncated or single-quoted JSON in tool arguments; double-encoded JSON strings; missing quotes around keys; wrong types (regex given as object).","solutions":["Validate the tool-call arguments are well-formed JSON before sending","Ensure all fetchLogsArgs fields have correct JSON types (strings for container_id, level, regex)","Check for truncation of long arguments and re-send the complete payload"],"exampleFix":"// before\nparseStreamArgs(`{container_id: web}`) // invalid JSON\n// after\nparseStreamArgs(`{\"container_id\": \"web\"}`)","handlingStrategy":"validation","validationCode":"if err := json.Valid([]byte(argsJSON)); err != nil { /* fix JSON before calling */ }","typeGuard":null,"tryCatchPattern":"resp, err := executeStreamLogs(ctx, deps, argsJSON, send)\nif err != nil && strings.Contains(err.Error(), \"failed to parse arguments\") {\n  // log raw argsJSON and re-send sanitized JSON\n}","preventionTips":["Serialize tool arguments with a JSON encoder, never string concatenation","Validate JSON before sending tool calls","Avoid single quotes and trailing commas in generated JSON"],"tags":["cloud-tools","json","argument-parsing"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"d9463cbe21874e44ab79db6fa63e746ca7d22928","analyzedAt":"2026-09-07T10:08:55.855Z","contentChangedAt":"2026-09-07T10:08:55.855Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}