mirror of
https://github.com/coredns/coredns.git
synced 2026-06-02 23:30:25 -04:00
fix: use descriptive error for unknown block options in health and log plugins (#8128)
This commit is contained in:
committed by
GitHub
parent
afdf121a5a
commit
0bcb17df06
@@ -86,7 +86,7 @@ func logParse(c *caddy.Controller) ([]Rule, error) {
|
||||
classes[cls] = struct{}{}
|
||||
}
|
||||
default:
|
||||
return nil, c.ArgErr()
|
||||
return nil, c.Errf("unknown property '%s'", c.Val())
|
||||
}
|
||||
}
|
||||
if len(classes) == 0 {
|
||||
|
||||
@@ -2,6 +2,7 @@ package log
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/coredns/caddy"
|
||||
@@ -182,3 +183,14 @@ func TestLogParse(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogParseUnknownProperty(t *testing.T) {
|
||||
c := caddy.NewTestController("dns", `log { unknown }`)
|
||||
_, err := logParse(c)
|
||||
if err == nil {
|
||||
t.Fatal("expected error for unknown block option, got nil")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "unknown property") {
|
||||
t.Errorf("expected error to contain 'unknown property', got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user