{"record":{"id":"5560ab58b1e8853d","repo":"wavetermdev/waveterm","slug":"invalid-input-format-w-5560ab","errorCode":null,"errorMessage":"invalid input format: %w","messagePattern":"invalid input format: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/aiusechat/tools_readfile.go","lineNumber":40,"sourceCode":"const StopReasonMaxBytes = \"max_bytes\"\n\ntype readTextFileParams struct {\n\tFilename string  `json:\"filename\"`\n\tOrigin   *string `json:\"origin\"` // \"start\" or \"end\", defaults to \"start\"\n\tOffset   *int    `json:\"offset\"` // lines to skip, defaults to 0\n\tCount    *int    `json:\"count\"`  // number of lines to read, defaults to DefaultLineCount\n\tMaxBytes *int    `json:\"max_bytes\"`\n}\n\nfunc parseReadTextFileInput(input any) (*readTextFileParams, error) {\n\tresult := &readTextFileParams{}\n\n\tif input == nil {\n\t\treturn nil, fmt.Errorf(\"input is required\")\n\t}\n\n\tif err := utilfn.ReUnmarshal(result, input); err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid input format: %w\", err)\n\t}\n\n\tif result.Filename == \"\" {\n\t\treturn nil, fmt.Errorf(\"missing filename parameter\")\n\t}\n\n\tif result.Origin == nil {\n\t\torigin := \"start\"\n\t\tresult.Origin = &origin\n\t}\n\n\tif *result.Origin != \"start\" && *result.Origin != \"end\" {\n\t\treturn nil, fmt.Errorf(\"invalid origin value '%s': must be 'start' or 'end'\", *result.Origin)\n\t}\n\n\tif result.Offset == nil {\n\t\toffset := 0\n\t\tresult.Offset = &offset","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/aiusechat/tools_readfile.go#L22-L58","documentation":"After unmarshaling the input into readTextFileParams via utilfn.ReUnmarshal, any shape/type mismatch returns this wrapped error. It means the input was present but was not a valid object conforming to the read_text_file parameter schema.","triggerScenarios":"Passing a string, array, or number as input; JSON with wrong types (e.g. \"offset\": \"5\" instead of a number); input not re-marshalable into the params struct.","commonSituations":"Agents quoting the whole argument set as a string; schema drift after library upgrades adding/renaming fields; JSON produced by a model with malformed types.","solutions":["Send a JSON object matching the schema: {filename, origin?, offset?, count?, maxBytes?}.","Ensure numeric fields (offset, count, maxBytes) are JSON numbers, not strings.","Log the underlying %w cause to identify the exact field that failed unmarshal."],"exampleFix":"// before\n{\"input\": \"{\\\"filename\\\": \\\"/a.txt\\\"}\"}\n// after\n{\"input\": {\"filename\": \"/a.txt\", \"offset\": 0}}","handlingStrategy":"validation","validationCode":"// validate shape client-side before sending\nfunction validReadInput(o) {\n  return typeof o === 'object' && o !== null &&\n    (o.offset === undefined || typeof o.offset === 'number') &&\n    (o.count === undefined || typeof o.count === 'number') &&\n    (o.maxBytes === undefined || typeof o.maxBytes === 'number');\n}","typeGuard":"func isReadTextFileInput(v any) bool {\n    var p readTextFileParams\n    return utilfn.ReUnmarshal(&p, v) == nil\n}","tryCatchPattern":"params, err := parseReadTextFileInput(input)\nif err != nil && strings.HasPrefix(err.Error(), \"invalid input format\") {\n    log.Printf(\"schema mismatch: %v\", err) // wrapped cause names the field\n}","preventionTips":["Match the documented JSON schema exactly","Send numbers as JSON numbers, never quoted strings","Re-check schema after library upgrades"],"tags":["input-validation","json","unmarshal"],"backgroundTag":"schema-validation-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}