registry: reject checker registration with empty ID
Prevent silent bugs where a CheckerDefinition with an unset ID would be registered under the empty string key, becoming unfindable and potentially colliding with other empty-ID registrations.
This commit is contained in:
parent
6be3578c33
commit
688d32cc9f
1 changed files with 4 additions and 0 deletions
|
|
@ -33,6 +33,10 @@ var observationProviderRegistry = map[ObservationKey]ObservationProvider{}
|
||||||
// always indicates a deployment mistake (two plugins shipping the same
|
// always indicates a deployment mistake (two plugins shipping the same
|
||||||
// checker, or a plugin shadowing a built-in).
|
// checker, or a plugin shadowing a built-in).
|
||||||
func RegisterChecker(c *CheckerDefinition) {
|
func RegisterChecker(c *CheckerDefinition) {
|
||||||
|
if c.ID == "" {
|
||||||
|
log.Println("Warning: refusing to register checker with empty ID")
|
||||||
|
return
|
||||||
|
}
|
||||||
if _, exists := checkerRegistry[c.ID]; exists {
|
if _, exists := checkerRegistry[c.ID]; exists {
|
||||||
log.Printf("Warning: checker %q is already registered; ignoring duplicate registration", c.ID)
|
log.Printf("Warning: checker %q is already registered; ignoring duplicate registration", c.ID)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue