AdguardTeam/AdGuardHome · error
unknown result code %d
Error message
unknown result code %d
What it means
Entry.validate rejects a stats entry whose Result code is set but >= resultLast, i.e. an unknown/enumeration-out-of-range result code.
Source
Thrown at internal/stats/unit.go:84
// UpstreamStats contains the DNS query statistics for both the upstream and
// fallback DNS servers. Don't modify items in the slice.
UpstreamStats []*proxy.UpstreamStatistics
// Result is the result of processing the request.
Result Result
// ProcessingTime is the duration of the request processing from the start
// of the request including timeouts.
ProcessingTime time.Duration
}
// validate returns an error if entry is not valid.
func (e *Entry) validate() (err error) {
switch {
case e.Result == 0:
return errors.Error("result code is not set")
case e.Result >= resultLast:
return fmt.Errorf("unknown result code %d", e.Result)
case e.Domain == "":
return errors.Error("domain is empty")
case e.Client == "":
return errors.Error("client is empty")
default:
return nil
}
}
// unit collects the statistics data for a specific period of time.
type unit struct {
// domains stores the number of requests for each domain.
domains map[string]uint64
// blockedDomains stores the number of requests for each domain that has
// been blocked.
blockedDomains map[string]uint64
View on GitHub (pinned to b41aefbe51)
Solutions
- Use the library's constants for result codes instead of raw numbers
- Upgrade/downgrade to matching versions across components writing stats entries
- Reject or skip unknown codes at ingestion instead of validating strictly
Example fix
// before
e := stats.Entry{Result: stats.ResultLast + 1, ...}
// after
e := stats.Entry{Result: stats.ResultFiltered, ...} Defensive patterns
Strategy: type-guard
Validate before calling
if e.Result == 0 || e.Result >= stats.ResultLast { return fmt.Errorf("bad result code %d", e.Result) } Type guard
func validResult(r stats.Result) bool { return r > 0 && r < stats.ResultLast } Try / catch
if err := e.Validate(); err != nil { /* drop entry, continue */ } Prevention
- Always assign Result from package constants
- Keep writer/reader versions in sync
When it happens
Trigger: Creating/validating an Entry with a Result value beyond the defined result codes (e.g. after new codes were appended and this build predates them, or manual construction with a bad code).
Common situations: Version skew: data written by a newer version with new result codes read/validated by an older build; hand-crafted entries in tests.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- unknown option type %q
- %s: must be a multiple of 1 hour
- json time is nil
- interface %s has no ipv6 addresses
- invalid ip version %d
AI-assisted analysis of AdguardTeam/AdGuardHome@b41aefbe51 (2026-08-27).
Data as JSON: /api/errors/304405e2e5332769.
Report an issue: GitHub.