{"record":{"id":"cbc136da03f9bb93","repo":"jquense/yup","slug":"yup-reach-cannot-resolve-an-array-item-at-index","errorCode":null,"errorMessage":"Yup.reach cannot resolve an array item at index: ${_part}, in the path: ${path}. because there is no value at that index. ","messagePattern":"Yup\\.reach cannot resolve an array item at index: (.+?), in the path: (.+?)\\. because there is no value at that index\\. ","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/util/reach.ts","lineNumber":35,"sourceCode":"\n  // root path: ''\n  if (!path) return { parent, parentPath: path, schema };\n\n  forEach(path, (_part, isBracket, isArray) => {\n    let part = isBracket ? _part.slice(1, _part.length - 1) : _part;\n\n    schema = schema.resolve({ context, parent, value });\n\n    let isTuple = schema.type === 'tuple';\n    let idx = isArray ? parseInt(part, 10) : 0;\n\n    if (schema.innerType || isTuple) {\n      if (isTuple && !isArray)\n        throw new Error(\n          `Yup.reach cannot implicitly index into a tuple type. the path part \"${lastPartDebug}\" must contain an index to the tuple element, e.g. \"${lastPartDebug}[0]\"`,\n        );\n      if (value && idx >= value.length) {\n        throw new Error(\n          `Yup.reach cannot resolve an array item at index: ${_part}, in the path: ${path}. ` +\n            `because there is no value at that index. `,\n        );\n      }\n      parent = value;\n      value = value && value[idx];\n      schema = isTuple ? schema.spec.types[idx] : schema.innerType!;\n    }\n\n    // sometimes the array index part of a path doesn't exist: \"nested.arr.child\"\n    // in these cases the current part is the next schema and should be processed\n    // in this iteration. For cases where the index signature is included this\n    // check will fail and we'll handle the `child` part on the next iteration like normal\n    if (!isArray) {\n      if (!schema.fields || !schema.fields[part])\n        throw new Error(\n          `The schema does not contain the path: ${path}. ` +\n            `(failed at: ${lastPartDebug} which is a type: \"${schema.type}\")`,","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/jquense/yup/blob/ff31eee8a2b10c938bb3a22544d9e33957a8cf01/src/util/reach.ts#L17-L53","documentation":"While resolving a path with an array index, reach()/getIn() checks that the actual runtime value actually has an element at that index. This Error is thrown when the index in the path is beyond the length of the current value (or the value exists but is too short).","triggerScenarios":"yup.reach(schema, 'items[5]', value) where value.items has fewer than 6 elements; idx (parsed from the path part) >= value.length.","commonSituations":"Hardcoded indices against variable-length arrays; empty arrays from an unfinished form; paths built dynamically with a stale index after data changed.","solutions":["Check the value's length before calling reach: value.items?.length > idx","Guard with optional chaining and skip reach when the element is absent","Use a smaller/default index or make the path length-agnostic","Ensure the value passed to reach() is the fully-populated one"],"exampleFix":"// before\nyup.reach(schema, 'items[3]', { items: [] }); // throws\n// after\nif ((data.items?.length ?? 0) > 3) yup.reach(schema, 'items[3]', data);","handlingStrategy":"validation","validationCode":"const m = path.match(/^(.*)\\[(\\d+)\\]$/);\nif (m) {\n  const arr = m[1].split('.').reduce((o, k) => o?.[k], data);\n  if (!Array.isArray(arr) || Number(m[2]) >= arr.length) return undefined;\n}","typeGuard":"function indexExists(value: unknown, idx: number): value is { length: number } & any[] {\n  return Array.isArray(value) && idx < value.length;\n}","tryCatchPattern":"try { return yup.reach(schema, path, value); } catch (e) { if (/no value at that index/.test(e.message)) return null; throw e; }","preventionTips":["Validate array length before reaching into indexed paths","Avoid hardcoding indices; compute them from the data","Re-run reach after any data mutation that changes array length"],"tags":["path-resolution","array-index","reach"],"backgroundTag":"array-index-out-of-bounds","analyzedSha":"ff31eee8a2b10c938bb3a22544d9e33957a8cf01","analyzedAt":"2026-08-31T21:51:03.773Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}