{"record":{"id":"a05722f4aed2d870","repo":"krahets/hello-algo","slug":"error-a05722","errorCode":null,"errorMessage":"индекс выходит за границы","messagePattern":"индекс выходит за границы","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ru/codes/go/chapter_array_and_linkedlist/my_list.go","lineNumber":39,"sourceCode":"\t\textendRatio: 2,               // Коэффициент увеличения списка при каждом расширении\n\t}\n}\n\n/* Получить длину списка (текущее число элементов) */\nfunc (l *myList) size() int {\n\treturn l.arrSize\n}\n\n/* Получить вместимость списка */\nfunc (l *myList) capacity() int {\n\treturn l.arrCapacity\n}\n\n/* Доступ к элементу */\nfunc (l *myList) get(index int) int {\n\t// Если индекс выходит за границы, выбрасывается исключение; далее аналогично\n\tif index < 0 || index >= l.arrSize {\n\t\tpanic(\"индекс выходит за границы\")\n\t}\n\treturn l.arr[index]\n}\n\n/* Обновление элемента */\nfunc (l *myList) set(num, index int) {\n\tif index < 0 || index >= l.arrSize {\n\t\tpanic(\"индекс выходит за границы\")\n\t}\n\tl.arr[index] = num\n}\n\n/* Добавление элемента в конец */\nfunc (l *myList) add(num int) {\n\t// При превышении вместимости по числу элементов запускается расширение\n\tif l.arrSize == l.arrCapacity {\n\t\tl.extendCapacity()\n\t}","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/go/chapter_array_and_linkedlist/my_list.go#L21-L57","documentation":"`get(index)` in the Russian `myList` panics with \"индекс выходит за границы\" (index out of bounds) when the position is outside `[0, arrSize-1]`. It is the read-side bounds guard of this tutorial dynamic array.","triggerScenarios":"Reading with `index < 0` or `index >= arrSize`; reading an empty list; using capacity rather than size for bounds math.","commonSituations":"Off-by-one loop bounds, `capacity()`/`size()` confusion, or a stale index kept across a mutating operation.","solutions":["Gate reads with `0 <= index < l.size()`.","Loop with `i < l.size()`, not `i <= l.size()`.","Use `size()` for valid-index arithmetic.","Recover at boundaries that accept caller indices."],"exampleFix":"// before\nv := l.get(i) // индекс выходит за границы\n\n// after\nif i >= 0 && i < l.size() {\n    v = l.get(i)\n}","handlingStrategy":"validation","validationCode":"if i < 0 || i >= l.size() {\n    return 0, errors.New(\"index out of bounds\")\n}\nreturn l.get(i), nil","typeGuard":"func (l *myList) validIndex(i int) bool {\n    return i >= 0 && i < l.arrSize\n}","tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        // return a zero value / error instead of crashing\n    }\n}()\nv = l.get(i)","preventionTips":["Use size(), not capacity(), for valid-index math.","Loop with `i < l.size()`.","Recompute indices after mutations."],"tags":["go","array-list","index-out-of-bounds","panic","teaching-example"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}