From b14a990922b93c271bd37aea9f331ed95cfe499b Mon Sep 17 00:00:00 2001 From: Solon Gordon Date: Mon, 16 Sep 2019 12:45:11 -0400 Subject: [PATCH] sql: improve error message for constraint parsing We used to throw a cryptic yaml error when zone config constraints could not be parsed. Now we return a friendlier error message which specifies what format was expected. Fixes #39784 Release justification: Low-risk error messaging improvement Release note: None --- pkg/config/zone_yaml.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/config/zone_yaml.go b/pkg/config/zone_yaml.go index d5b025e9919a..fddeb24f786a 100644 --- a/pkg/config/zone_yaml.go +++ b/pkg/config/zone_yaml.go @@ -16,8 +16,9 @@ import ( "sort" "strings" - proto "github.com/gogo/protobuf/proto" - yaml "gopkg.in/yaml.v2" + "github.com/cockroachdb/errors" + "github.com/gogo/protobuf/proto" + "gopkg.in/yaml.v2" ) var _ yaml.Marshaler = LeasePreference{} @@ -141,7 +142,8 @@ func (c *ConstraintsList) UnmarshalYAML(unmarshal func(interface{}) error) error // constraints. constraintsMap := make(map[string]int32) if err := unmarshal(&constraintsMap); err != nil { - return err + return errors.New( + "invalid constraints format. expected an array of strings or a map of strings to ints") } constraintsList := make([]Constraints, 0, len(constraintsMap))