AdguardTeam/AdGuardHome · error

panic: %w

Error message

panic: %w

What it means

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).

Source

Thrown at internal/stats/stats.go:227

	s.curr.deserialize(udb)

	s.logger.Debug("initialized")

	return s, nil
}

// withRecovered turns the value recovered from panic if any into an error and
// combines it with the one pointed by orig.  orig must be non-nil.
func withRecovered(orig *error) {
	p := recover()
	if p == nil {
		return
	}

	var err error
	switch p := p.(type) {
	case error:
		err = fmt.Errorf("panic: %w", p)
	default:
		err = fmt.Errorf("panic: recovered value of type %[1]T: %[1]v", p)
	}

	*orig = errors.WithDeferred(*orig, err)
}

// type check
var _ Interface = (*StatsCtx)(nil)

// Start implements the [Interface] interface for *StatsCtx.
func (s *StatsCtx) Start() {
	s.initWeb()

	go s.periodicFlush()
}

// Close implements the [io.Closer] interface for *StatsCtx.

View on GitHub (pinned to b41aefbe51)

Solutions

  1. Inspect the wrapped panic value and stack trace to find the panicking call
  2. Verify all required Config fields (ShouldCountClient etc.) are set before calling New
  3. Report/check for a fixed version if the panic originates inside the library
Defensive patterns

Strategy: try-catch

Validate before calling

if conf.ShouldCountClient == nil { return errors.New("ShouldCountClient required") }

Try / catch

defer func() { if r := recover(); r != nil { log.Printf("panic: %v", r) } }()

Prevention

When it happens

Trigger: 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).

Common situations: Internal bugs or nil configuration fields causing a panic during initialization; bbolt/gob panicking on unexpected state.

Related errors


AI-assisted analysis of AdguardTeam/AdGuardHome@b41aefbe51 (2026-08-27). Data as JSON: /api/errors/4d21ed3226326bdc. Report an issue: GitHub.