From db1839a6e9b7d6a86ae334fa7bcae5e3aa622295 Mon Sep 17 00:00:00 2001 From: "Julien Tant (aider)" Date: Wed, 12 Feb 2025 13:18:51 -0700 Subject: [PATCH] feat: Add index number to validation error messages in custom profile attributes --- server/public/model/custom_profile_attributes.go | 7 ++++--- server/public/model/custom_profile_attributes_test.go | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/server/public/model/custom_profile_attributes.go b/server/public/model/custom_profile_attributes.go index 7b0600bd9b..cf09191de0 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 8c1b454861..0c43a1048e 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", }, }