ipfs/kubo · error
cannot have negative byte count
Error message
cannot have negative byte count
What it means
Guard in the `ipfs files write` handler after truncation handling: a --count option parsed to a negative int64 is rejected before seeking and writing. Validation of the byte-count option, not an I/O failure.
Source
Thrown at core/commands/files.go:1152
if _, err := mfs.FlushPath(req.Context, nd.FilesRoot, parent); err != nil {
if retErr == nil {
retErr = err
} else {
flog.Error("files: flushing the parent folder", err)
}
}
}
}()
if trunc {
if err := wfd.Truncate(0); err != nil {
return err
}
}
count, countfound := req.Options[filesCountOptionName].(int64)
if countfound && count < 0 {
return fmt.Errorf("cannot have negative byte count")
}
_, err = wfd.Seek(int64(offset), io.SeekStart)
if err != nil {
flog.Error("seekfail: ", err)
return err
}
var r io.Reader
r, err = cmdenv.GetFileArg(req.Files.Entries())
if err != nil {
return err
}
if countfound {
r = io.LimitReader(r, int64(count))
}
_, err = io.Copy(wfd, r)View on GitHub (pinned to 329838acdf)
Solutions
- Pass a non-negative --count, or omit it to write until the input ends.
- Fix the script or wrapper that derives the count value so it cannot be negative.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at core/commands/files.go:1152 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03).
Data as JSON: /api/errors/81484ca4e381e2b7.
Report an issue: GitHub.