From 77dfb8231308a3a464fad4b07acd8afadea55c74 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Thu, 30 Apr 2026 09:17:01 +0700 Subject: [PATCH] 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. --- checker/provider.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/checker/provider.go b/checker/provider.go index ad7e3b3..a7d9825 100644 --- a/checker/provider.go +++ b/checker/provider.go @@ -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) }