mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
feat: Add index number to validation error messages in custom profile attributes
This commit is contained in:
@@ -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{}{}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user