inancgumus/learngo · error
record.page cannot be empty
Error message
record.page cannot be empty
What it means
Sentinel validation error from the pipe package's internal validate() guard: after a record is decoded (via UnmarshalText or UnmarshalJSON), the page field is the empty string. It fires because the decoded log record lacks a page path, which the parser requires as a mandatory column alongside domain; the record is rejected before it is aggregated.
Source
Thrown at logparser/v5/pipe/record.go:98
return json.Marshal(rj)
}
// parseStr helps UnmarshalText for string to positive int parsing.
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
- Ensure each record has a non-empty page value before unmarshaling.
- Default missing pages to a sentinel like "/unknown" if acceptable.
- Trim input; if whitespace-only pages should count, fill a value upstream.
- Skip and log invalid records instead of failing.
Example fix
// before
{"domain":"example.com","visits":10}
// after
{"domain":"example.com","page":"/","visits":10} Defensive patterns
Strategy: validation
Validate before calling
if strings.TrimSpace(rec.Page) == "" {
rec.Page = "/unknown" // or reject
} Type guard
func hasPage(r record) bool { return strings.TrimSpace(r.page) != "" } Try / catch
var rec record
err := rec.UnmarshalJSON(data)
if err != nil {
if strings.Contains(err.Error(), "record.page cannot be empty") {
log.Printf("dropping record without page: %s", data)
return nil
}
return err
} Prevention
- Ensure log exporters always emit the page/path field
- Normalize empty paths to "/" upstream
- Trim fields before unmarshaling
- Test with records missing each field individually
When it happens
Trigger: UnmarshalText/UnmarshalJSON receive a record where page is missing, null, or "" (while domain is non-empty, since domain is checked first).
Common situations: Log lines missing the URL/path column; JSON exporters emitting records without the page key; rows where the page was trimmed to nothing.
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.domain cannot be empty
- record.domain cannot be empty|record.page cannot be empty|re
- invalid number
- record.visits cannot be negative
- record.uniques cannot be negative
AI-assisted analysis of inancgumus/learngo@3c475a78e5 (2026-09-02).
Data as JSON: /api/errors/9ce4fe82d655784f.
Report an issue: GitHub.