fix: return ErrNoCollector instead of panicking on nil CollectFn

Hosts that register the provider only for its definition (externalizable
checker) construct it with a nil CollectFn. If the local ObservationContext
ends up calling Collect, the previous code dereferenced a nil function
value and crashed the goroutine. Surface a typed error so rules degrade
to a clean StatusError state.
This commit is contained in:
nemunaire 2026-04-30 09:17:01 +07:00
commit 77dfb82313

View file

@ -4,10 +4,16 @@ package checker
import (
"context"
"errors"
sdk "git.happydns.org/checker-sdk-go/checker"
)
// ErrNoCollector is returned by Collect when the provider was constructed
// without a CollectFn (e.g. when registered host-side as an externalizable-only
// provider). Callers should route the observation to an external checker.
var ErrNoCollector = errors.New("dnsviz: provider has no local collector; use an external checker")
// CollectFn is the function signature for the DNSViz data collection step.
// The checker package is decoupled from the subprocess invocation so it can
// be imported without GPL obligations. Implementations live in the binary or
@ -27,5 +33,8 @@ func (p *dnsvizProvider) Key() sdk.ObservationKey {
}
func (p *dnsvizProvider) Collect(ctx context.Context, opts sdk.CheckerOptions) (any, error) {
if p.collect == nil {
return nil, ErrNoCollector
}
return p.collect(ctx, opts)
}