{"record":{"id":"4d21ed3226326bdc","repo":"AdguardTeam/AdGuardHome","slug":"panic-w","errorCode":null,"errorMessage":"panic: %w","messagePattern":"panic: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/stats/stats.go","lineNumber":227,"sourceCode":"\ts.curr.deserialize(udb)\n\n\ts.logger.Debug(\"initialized\")\n\n\treturn s, nil\n}\n\n// withRecovered turns the value recovered from panic if any into an error and\n// combines it with the one pointed by orig.  orig must be non-nil.\nfunc withRecovered(orig *error) {\n\tp := recover()\n\tif p == nil {\n\t\treturn\n\t}\n\n\tvar err error\n\tswitch p := p.(type) {\n\tcase error:\n\t\terr = fmt.Errorf(\"panic: %w\", p)\n\tdefault:\n\t\terr = fmt.Errorf(\"panic: recovered value of type %[1]T: %[1]v\", p)\n\t}\n\n\t*orig = errors.WithDeferred(*orig, err)\n}\n\n// type check\nvar _ Interface = (*StatsCtx)(nil)\n\n// Start implements the [Interface] interface for *StatsCtx.\nfunc (s *StatsCtx) Start() {\n\ts.initWeb()\n\n\tgo s.periodicFlush()\n}\n\n// Close implements the [io.Closer] interface for *StatsCtx.","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/AdguardTeam/AdGuardHome/blob/b41aefbe51c8dde65e2c50f093996afa0502edf9/internal/stats/stats.go#L209-L245","documentation":"withRecovered converts a recovered panic into an error. When the panic value implements error, it is wrapped as 'panic: %w' and attached via errors.WithDeferred to the function's returned error (used by stats.New).","triggerScenarios":"Any panic inside stats.New whose recovered value is an error type (e.g. a nil-pointer deref on an internal error path or an error-typed panic from a dependency).","commonSituations":"Internal bugs or nil configuration fields causing a panic during initialization; bbolt/gob panicking on unexpected state.","solutions":["Inspect the wrapped panic value and stack trace to find the panicking call","Verify all required Config fields (ShouldCountClient etc.) are set before calling New","Report/check for a fixed version if the panic originates inside the library"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if conf.ShouldCountClient == nil { return errors.New(\"ShouldCountClient required\") }","typeGuard":null,"tryCatchPattern":"defer func() { if r := recover(); r != nil { log.Printf(\"panic: %v\", r) } }()","preventionTips":["Fill all Config fields before New","Keep library version aligned with stored data"],"tags":["stats","panic","recovery"],"backgroundTag":"recovered-panic","analyzedSha":"b41aefbe51c8dde65e2c50f093996afa0502edf9","analyzedAt":"2026-08-27T04:57:55.097Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}