Skip to content

Commit bbb5a04

Browse files
Merge branch 'master' into enum-parsing
2 parents 0170923 + c3966be commit bbb5a04

File tree

6 files changed

+66
-9
lines changed

6 files changed

+66
-9
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ beta releases are not included in this history.
1414

1515
[//]: # (begin_release_notes)
1616

17+
"1.131.1" (2025-10-30)
18+
======================
19+
20+
Bugfixes
21+
--------
22+
23+
- Fix bug with config validation incorrectly generating error messages omitting the field name segment (#1727)
24+
- Dependency upgrade: v5-5.4.0 (#20251030110347)
25+
26+
1727
"1.131.0" (2025-10-27)
1828
======================
1929

utils/config/error.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type validationError struct {
5656
mapStructureTree []string
5757
mapStructurePrefix *string
5858
reason string
59+
fieldName string
5960
}
6061

6162
func (v *validationError) GetTree() []string {
@@ -80,9 +81,11 @@ func (v *validationError) RecordField(fieldName string, mapStructureFieldName *s
8081
treeMap = append(treeMap, strings.ToUpper(strings.TrimSpace(*mapStructureFieldName)))
8182
treeMap = append(treeMap, v.mapStructureTree...)
8283
v.mapStructureTree = treeMap
84+
} else {
85+
v.fieldName = fieldName
8386
}
84-
v.mapStructurePrefix = mapStructurePrefix
8587

88+
v.mapStructurePrefix = mapStructurePrefix
8689
}
8790

8891
func (v *validationError) RecordPrefix(mapStructurePrefix string) {
@@ -114,6 +117,10 @@ func (v *validationError) GetMapStructurePath() string {
114117
if v.mapStructurePrefix != nil {
115118
mapstructureStr = fmt.Sprintf("%v_%v", strings.ToUpper(strings.TrimSpace(*v.mapStructurePrefix)), mapstructureStr)
116119
}
120+
121+
if v.fieldName != "" {
122+
mapstructureStr = fmt.Sprintf("%v_%v", mapstructureStr, strings.ToUpper(strings.TrimSpace(v.fieldName)))
123+
}
117124
}
118125
return mapstructureStr
119126
}

utils/config/service_configuration_test.go

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,15 @@ func DefaultDeepConfiguration() *DeepConfig {
9191
}
9292

9393
func (cfg *DeepConfig) Validate() error {
94-
return nil
94+
// Validate Embedded Structs
95+
err := ValidateEmbedded(cfg)
96+
if err != nil {
97+
return err
98+
}
99+
100+
return validation.ValidateStruct(cfg,
101+
validation.Field(&cfg.TestConfigDeep, validation.Required),
102+
)
95103
}
96104

97105
func (cfg *ConfigurationTest) Validate() error {
@@ -125,8 +133,37 @@ func TestErrorFormatting(t *testing.T) {
125133
cfg := DefaultConfiguration()
126134
err := cfg.Validate()
127135
require.Error(t, err)
136+
137+
errortest.AssertError(t, err, commonerrors.ErrInvalid)
138+
assert.Contains(t, err.Error(), "invalid: structure failed validation: (TestConfig->db) [DUMMYCONFIG_DB] cannot be blank")
139+
}
140+
141+
func TestDeepErrorFormatting(t *testing.T) {
142+
defaults := DefaultDeepConfiguration()
143+
err := defaults.Validate()
144+
require.Error(t, err)
145+
128146
errortest.AssertError(t, err, commonerrors.ErrInvalid)
129-
assert.Contains(t, err.Error(), "invalid: structure failed validation: (TestConfig->db) [DUMMYCONFIG] cannot be blank")
147+
assert.Contains(t, err.Error(), "invalid: structure failed validation: (TestConfigDeep->TestConfig->db) [DEEP_CONFIG_DUMMYCONFIG_DB] cannot be blank")
148+
149+
err = os.Setenv("TEST_DEEP_CONFIG_DUMMYCONFIG_DB", "a test db")
150+
require.NoError(t, err)
151+
err = os.Setenv("TEST_DEEP_CONFIG_DUMMYCONFIG_DUMMY_HOST", "a test host")
152+
require.NoError(t, err)
153+
err = os.Setenv("TEST_DEEP_CONFIG_DUMMYCONFIG_PASSWORD", "a test password")
154+
require.NoError(t, err)
155+
err = os.Setenv("TEST_DEEP_CONFIG_DUMMYCONFIG_USER", "a test user")
156+
require.NoError(t, err)
157+
err = os.Setenv("TEST_DEEP_CONFIG_DUMMY_CONFIG_DB", "a test user")
158+
require.NoError(t, err)
159+
160+
t.Run("defined mapstructure", func(t *testing.T) {
161+
configTest2 := &DeepConfig{}
162+
err = LoadFromSystem("test", configTest2, defaults)
163+
164+
errortest.AssertError(t, err, commonerrors.ErrInvalid)
165+
assert.Contains(t, err.Error(), "invalid: structure failed validation: (TestConfigDeep->TestConfig2->dummy_host) [TEST_DEEP_CONFIG_DUMMY_CONFIG_DUMMY_HOST] cannot be blank")
166+
})
130167
}
131168

132169
func TestServiceConfigurationLoad(t *testing.T) {
@@ -137,6 +174,9 @@ func TestServiceConfigurationLoad(t *testing.T) {
137174
err := Load("test", configTest, defaults)
138175
// Some required values are missing.
139176
require.Error(t, err)
177+
178+
assert.ErrorContains(t, err, "(TestConfig->db) [TEST_DUMMYCONFIG_DB] cannot be blank")
179+
140180
errortest.RequireError(t, err, commonerrors.ErrInvalid)
141181
errortest.RequireError(t, configTest.Validate(), commonerrors.ErrInvalid)
142182

utils/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/go-logr/zapr v1.3.0
2323
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
2424
github.com/go-viper/mapstructure/v2 v2.4.0
25-
github.com/gofrs/uuid/v5 v5.3.2
25+
github.com/gofrs/uuid/v5 v5.4.0
2626
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f
2727
github.com/hashicorp/go-cleanhttp v0.5.2
2828
github.com/hashicorp/go-hclog v1.6.3

utils/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ github.com/godbus/dbus v4.1.0+incompatible/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZ
9999
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
100100
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
101101
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
102-
github.com/gofrs/uuid/v5 v5.3.2 h1:2jfO8j3XgSwlz/wHqemAEugfnTlikAYHhnqQ8Xh4fE0=
103-
github.com/gofrs/uuid/v5 v5.3.2/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
102+
github.com/gofrs/uuid/v5 v5.4.0 h1:EfbpCTjqMuGyq5ZJwxqzn3Cbr2d0rUZU7v5ycAk/e/0=
103+
github.com/gofrs/uuid/v5 v5.4.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
104104
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f h1:3BSP1Tbs2djlpprl7wCLuiqMaUh5SJkkzI2gDs+FgLs=
105105
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f/go.mod h1:Pcatq5tYkCW2Q6yrR2VRHlbHpZ/R4/7qyL1TCF7vl14=
106106
github.com/golang/glog v0.0.0-20210429001901-424d2337a529/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=

utils/module.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Version=1.131.0
1+
Version=1.131.1
22
MajorVersion=1
33
MinorVersion=131
4-
PatchVersion=0
5-
CommitHash=7b5785efbcef070d14a6479e3097c7861cfb537e
4+
PatchVersion=1
5+
CommitHash=4c3b0e9f017c84cfeaee68bfb286e02feebd1fce

0 commit comments

Comments
 (0)