{"record":{"id":"304405e2e5332769","repo":"AdguardTeam/AdGuardHome","slug":"unknown-result-code-d","errorCode":null,"errorMessage":"unknown result code %d","messagePattern":"unknown result code (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/stats/unit.go","lineNumber":84,"sourceCode":"\t// UpstreamStats contains the DNS query statistics for both the upstream and\n\t// fallback DNS servers.  Don't modify items in the slice.\n\tUpstreamStats []*proxy.UpstreamStatistics\n\n\t// Result is the result of processing the request.\n\tResult Result\n\n\t// ProcessingTime is the duration of the request processing from the start\n\t// of the request including timeouts.\n\tProcessingTime time.Duration\n}\n\n// validate returns an error if entry is not valid.\nfunc (e *Entry) validate() (err error) {\n\tswitch {\n\tcase e.Result == 0:\n\t\treturn errors.Error(\"result code is not set\")\n\tcase e.Result >= resultLast:\n\t\treturn fmt.Errorf(\"unknown result code %d\", e.Result)\n\tcase e.Domain == \"\":\n\t\treturn errors.Error(\"domain is empty\")\n\tcase e.Client == \"\":\n\t\treturn errors.Error(\"client is empty\")\n\tdefault:\n\t\treturn nil\n\t}\n}\n\n// unit collects the statistics data for a specific period of time.\ntype unit struct {\n\t// domains stores the number of requests for each domain.\n\tdomains map[string]uint64\n\n\t// blockedDomains stores the number of requests for each domain that has\n\t// been blocked.\n\tblockedDomains map[string]uint64\n","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/AdguardTeam/AdGuardHome/blob/b41aefbe51c8dde65e2c50f093996afa0502edf9/internal/stats/unit.go#L66-L102","documentation":"Entry.validate rejects a stats entry whose Result code is set but >= resultLast, i.e. an unknown/enumeration-out-of-range result code.","triggerScenarios":"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).","commonSituations":"Version skew: data written by a newer version with new result codes read/validated by an older build; hand-crafted entries in tests.","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"],"exampleFix":"// before\ne := stats.Entry{Result: stats.ResultLast + 1, ...}\n// after\ne := stats.Entry{Result: stats.ResultFiltered, ...}","handlingStrategy":"type-guard","validationCode":"if e.Result == 0 || e.Result >= stats.ResultLast { return fmt.Errorf(\"bad result code %d\", e.Result) }","typeGuard":"func validResult(r stats.Result) bool { return r > 0 && r < stats.ResultLast }","tryCatchPattern":"if err := e.Validate(); err != nil { /* drop entry, continue */ }","preventionTips":["Always assign Result from package constants","Keep writer/reader versions in sync"],"tags":["stats","validation","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"b41aefbe51c8dde65e2c50f093996afa0502edf9","analyzedAt":"2026-08-27T04:57:55.097Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}