Skip to content

Commit 830adb1

Browse files
committed
check if path exists before continuing
1 parent e5bbd77 commit 830adb1

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

utils/config/config.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,29 @@ func transformChildrenUnderArray(config *koanf.Koanf, root string, subPath strin
173173
"item": array[i],
174174
}, "."), nil)
175175

176-
if err := transformChildren(tmp, "item." + subPath, transform); err != nil {
177-
return err
176+
path := "item." + subPath
177+
178+
exists := tmp.Exists(path)
179+
180+
if !exists {
181+
tmp.Load(confmap.Provider(map[string]any{
182+
"item": map[string]any{
183+
subPath: map[string]any{},
184+
},
185+
}, "."), nil)
178186
}
179187

180-
array[i] = tmp.All()["item"].(map[string]any)
188+
transformChildren(tmp, path, transform)
189+
190+
item := tmp.All()["item"]
191+
192+
itemMap, ok := item.(map[string]any)
193+
194+
if ok {
195+
array[i] = itemMap
196+
} else {
197+
array[i] = map[string]any{}
198+
}
181199
}
182200

183201
config.Load(confmap.Provider(map[string]any{

0 commit comments

Comments
 (0)