inancgumus/learngo · error
record.uniques cannot be negative
Error message
record.uniques cannot be negative
What it means
Sentinel validation error from the pipe package's internal validate() guard: a decoded record has a negative uniques value. It fires when the uniques column in JSON or text input is below zero; like visits, uniques is a count and must be non-negative, so validate() rejects the record.
Source
Thrown at logparser/v5/pipe/record.go:102
func parseStr(name, v string) (int, error) {
n, err := strconv.Atoi(v)
if err != nil {
return 0, fmt.Errorf("Record.UnmarshalText %q: %v", name, err)
}
return n, nil
}
// validate whether a parsed record is valid or not.
func validate(r record) (err error) {
switch {
case r.domain == "":
err = errors.New("record.domain cannot be empty")
case r.page == "":
err = errors.New("record.page cannot be empty")
case r.visits < 0:
err = errors.New("record.visits cannot be negative")
case r.uniques < 0:
err = errors.New("record.uniques cannot be negative")
}
return
}
View on GitHub (pinned to 3c475a78e5)
Solutions
- Clamp or fix negative uniques at the data source.
- Audit upstream diff/aggregation logic for subtraction that can go negative.
- Skip and log offending records during ingestion.
- Relax the check only if negative uniques are valid in your pipeline.
Example fix
// before
{"domain":"example.com","page":"/","uniques":-1}
// after
{"domain":"example.com","page":"/","uniques":0} Defensive patterns
Strategy: validation
Validate before calling
if rec.Uniques < 0 {
rec.Uniques = 0 // clamp, or reject the record
} Type guard
func hasValidUniques(r record) bool { return r.uniques >= 0 } Try / catch
var rec record
err := rec.UnmarshalJSON(data)
if err != nil {
if strings.Contains(err.Error(), "record.uniques cannot be negative") {
log.Printf("dropping record with negative uniques: %s", data)
return nil
}
return err
} Prevention
- Clamp uniques at the source; never subtract counts below zero
- Validate inputs before UnmarshalText/UnmarshalJSON
- Monitor ingestion for negative-counter anomalies
- Skip-and-log invalid rows rather than failing batches
When it happens
Trigger: Unmarshaling a record where uniques < 0, e.g. "uniques": -2 in JSON or a negative text field in the uniques column.
Common situations: Same ETL/diff bugs as visits: subtracting counts, bad manual edits, or signed-column misparse during import.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- record.visits cannot be negative
- invalid number
- record.domain cannot be empty
- record.page cannot be empty
- record.domain cannot be empty|record.page cannot be empty|re
AI-assisted analysis of inancgumus/learngo@3c475a78e5 (2026-09-02).
Data as JSON: /api/errors/bd8050fb72bbfbbd.
Report an issue: GitHub.