MCPcopy
hub / github.com/helm/helm / setIndex

Function setIndex

pkg/strvals/parser.go:299–322  ·  view source on GitHub ↗
(list []any, index int, val any)

Source from the content-addressed store, hash-verified

297}
298
299func setIndex(list []any, index int, val any) (l2 []any, err error) {
300 // There are possible index values that are out of range on a target system
301 // causing a panic. This will catch the panic and return an error instead.
302 // The value of the index that causes a panic varies from system to system.
303 defer func() {
304 if r := recover(); r != nil {
305 err = fmt.Errorf("error processing index %d: %s", index, r)
306 }
307 }()
308
309 if index < 0 {
310 return list, fmt.Errorf("negative %d index not allowed", index)
311 }
312 if index > MaxIndex {
313 return list, fmt.Errorf("index of %d is greater than maximum supported index of %d", index, MaxIndex)
314 }
315 if len(list) <= index {
316 newlist := make([]any, index+1)
317 copy(newlist, list)
318 list = newlist
319 }
320 list[index] = val
321 return list, nil
322}
323
324func (t *parser) keyIndex() (int, error) {
325 // First, get the key.

Callers 3

listItemMethod · 0.85
TestSetIndexFunction · 0.85
listItemMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestSetIndexFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…