diff --git a/server/public/model/custom_profile_attributes.go b/server/public/model/custom_profile_attributes.go index 7b0600bd9b8..cf09191de07 100644 --- a/server/public/model/custom_profile_attributes.go +++ b/server/public/model/custom_profile_attributes.go @@ -5,6 +5,7 @@ package model import ( "errors" + "fmt" "strings" ) @@ -111,13 +112,13 @@ func (c CustomProfileAttributesSelectOptions) IsValid() error { } seenNames := make(map[string]struct{}) - for _, option := range c { + for i, option := range c { if err := option.IsValid(); err != nil { - return err + return fmt.Errorf("invalid option at index %d: %w", i, err) } if _, exists := seenNames[option.Name]; exists { - return errors.New("duplicate option name found") + return fmt.Errorf("duplicate option name found at index %d: %s", i, option.Name) } seenNames[option.Name] = struct{}{} } diff --git a/server/public/model/custom_profile_attributes_test.go b/server/public/model/custom_profile_attributes_test.go index 8c1b4548619..0c43a1048e3 100644 --- a/server/public/model/custom_profile_attributes_test.go +++ b/server/public/model/custom_profile_attributes_test.go @@ -49,7 +49,7 @@ func TestCustomProfileAttributeSelectOptionIsValid(t *testing.T) { Name: "Test Option", Color: "#FF0000", }, - wantErr: "id cannot be empty", + wantErr: "invalid option at index 1: id cannot be empty", }, { name: "invalid ID", @@ -149,7 +149,7 @@ func TestCustomProfileAttributesSelectOptionsIsValid(t *testing.T) { Color: "#00FF00", }, }, - wantErr: "duplicate option name found", + wantErr: "duplicate option name found at index 1: Option 1", }, }