{"record":{"id":"11cf116f4c2e9338","repo":"wavetermdev/waveterm","slug":"count-must-be-at-least-1-got-d","errorCode":null,"errorMessage":"count must be at least 1, got %d","messagePattern":"count must be at least 1, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/aiusechat/tools_readfile.go","lineNumber":71,"sourceCode":"\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\n\t}\n\n\tif *result.Offset < 0 {\n\t\treturn nil, fmt.Errorf(\"offset must be non-negative, got %d\", *result.Offset)\n\t}\n\n\tif result.Count == nil {\n\t\tcount := ReadFileDefaultLineCount\n\t\tresult.Count = &count\n\t}\n\n\tif *result.Count < 1 {\n\t\treturn nil, fmt.Errorf(\"count must be at least 1, got %d\", *result.Count)\n\t}\n\n\tif result.MaxBytes == nil {\n\t\tmaxBytes := ReadFileDefaultMaxBytes\n\t\tresult.MaxBytes = &maxBytes\n\t}\n\n\treturn result, nil\n}\n\n// truncateData truncates data to maxBytes while respecting line boundaries.\n// For origin \"start\", keeps the beginning and truncates at last newline before maxBytes.\n// For origin \"end\", keeps the end and truncates from beginning at first newline after removing excess.\nfunc truncateData(data string, origin string, maxBytes int) string {\n\tif len(data) <= maxBytes {\n\t\treturn data\n\t}\n","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/aiusechat/tools_readfile.go#L53-L89","documentation":"Validation error: the count parameter is less than 1, which would read nothing.","triggerScenarios":"Passing {\"count\": 0} or negative values; computing count = endLine - startLine where endLine == startLine.","commonSituations":"Range-based reading scripts where the requested range is empty; agents setting count 0 expecting \"unlimited\" (use maxBytes or omit instead); template bugs generating 0.","solutions":["Set count >= 1 (e.g. clamp with Math.max(1, count)).","Omit \"count\" to use ReadFileDefaultLineCount.","If you want all remaining lines, don't send count 0 — send a large count or adjust maxBytes."],"exampleFix":"// before\n{\"filename\": \"/tmp/a.txt\", \"count\": 0}\n// after\nconst count = Math.max(1, endLine - startLine || 1);\nread_text_file({\"filename\": \"/tmp/a.txt\", \"count\": count})","handlingStrategy":"validation","validationCode":"const safeCount = Number.isInteger(count) && count >= 1 ? count : undefined;","typeGuard":"func validCount(c int) bool { return c >= 1 }","tryCatchPattern":"params, err := parseReadTextFileInput(input)\nif err != nil && strings.HasPrefix(err.Error(), \"count must be at least 1\") {\n    // clamp to 1 or drop the param to use the default\n}","preventionTips":["Clamp computed ranges: count = Math.max(1, end-start)","Omit count to use ReadFileDefaultLineCount","Don't use 0 to mean unlimited — it is rejected"],"tags":["input-validation","numeric-range","tooling"],"backgroundTag":"invalid-argument-value","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}