wavetermdev/waveterm · error
count must be at least 1, got %d
Error message
count must be at least 1, got %d
What it means
Validation error: the count parameter is less than 1, which would read nothing.
Source
Thrown at pkg/aiusechat/tools_readfile.go:71
return nil, fmt.Errorf("invalid origin value '%s': must be 'start' or 'end'", *result.Origin)
}
if result.Offset == nil {
offset := 0
result.Offset = &offset
}
if *result.Offset < 0 {
return nil, fmt.Errorf("offset must be non-negative, got %d", *result.Offset)
}
if result.Count == nil {
count := ReadFileDefaultLineCount
result.Count = &count
}
if *result.Count < 1 {
return nil, fmt.Errorf("count must be at least 1, got %d", *result.Count)
}
if result.MaxBytes == nil {
maxBytes := ReadFileDefaultMaxBytes
result.MaxBytes = &maxBytes
}
return result, nil
}
// truncateData truncates data to maxBytes while respecting line boundaries.
// For origin "start", keeps the beginning and truncates at last newline before maxBytes.
// For origin "end", keeps the end and truncates from beginning at first newline after removing excess.
func truncateData(data string, origin string, maxBytes int) string {
if len(data) <= maxBytes {
return data
}
View on GitHub (pinned to a4447c1563)
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.
Example fix
// before
{"filename": "/tmp/a.txt", "count": 0}
// after
const count = Math.max(1, endLine - startLine || 1);
read_text_file({"filename": "/tmp/a.txt", "count": count}) Defensive patterns
Strategy: validation
Validate before calling
const safeCount = Number.isInteger(count) && count >= 1 ? count : undefined;
Type guard
func validCount(c int) bool { return c >= 1 } Try / catch
params, err := parseReadTextFileInput(input)
if err != nil && strings.HasPrefix(err.Error(), "count must be at least 1") {
// clamp to 1 or drop the param to use the default
} Prevention
- Clamp computed ranges: count = Math.max(1, end-start)
- Omit count to use ReadFileDefaultLineCount
- Don't use 0 to mean unlimited — it is rejected
When it happens
Trigger: Passing {"count": 0} or negative values; computing count = endLine - startLine where endLine == startLine.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- offset must be non-negative, got %d
- input is required
- missing filename parameter
- invalid origin value '%s': must be 'start' or 'end'
- integer overflow
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/11cf116f4c2e9338.
Report an issue: GitHub.