diff --git a/edge_test.go b/edge_test.go index 80e0f7d..c83d92c 100644 --- a/edge_test.go +++ b/edge_test.go @@ -91,7 +91,7 @@ func TestNewErrors(t *testing.T) { }, "an option name used as a token": { map[string]string{"a": `{"format":"{weight}"}`}, - `"weight" is an option, never a field`, + `"weight" is an option and can never be a field`, }, "category name with a dot": { map[string]string{"a.b": `["1"]`}, diff --git a/node.go b/node.go index 228225b..f7ac73e 100644 --- a/node.go +++ b/node.go @@ -51,13 +51,11 @@ type template struct { func (*template) isNode() {} // compile converts parsed JSON into a node tree, validating structure up front. -// Only a choice's items carry a weight, so a numeric one here would be inert. +// Only a choice's items carry a weight, so one here would be inert whatever its type. func compile(v any) (node, error) { if m, ok := v.(map[string]any); ok { - if w, weighted := m["weight"]; weighted { - if _, isNumber := w.(float64); isNumber { - return nil, fmt.Errorf("weight only skews a choice's items, so it has no effect here") - } + if _, weighted := m["weight"]; weighted { + return nil, fmt.Errorf("weight only skews a choice's items, so it has no effect here; it is an option and can never be a field") } } return compileItem(v) diff --git a/template.go b/template.go index bc7b7ce..41cb788 100644 --- a/template.go +++ b/template.go @@ -144,7 +144,7 @@ func checkTokens(format string, fields map[string]node) error { } if _, ok := fields[name]; !ok { if isOption(name) { - return fmt.Errorf("token {%s}: %q is an option, never a field", t.body, name) + return fmt.Errorf("token {%s}: %q is an option and can never be a field", t.body, name) } return fmt.Errorf("token {%s}: no field %q", t.body, name) }