{"record":{"id":"fd38b847d4849d65","repo":"antonmedv/fx","slug":"cannot-reverse-typeof-x","errorCode":null,"errorMessage":"Cannot reverse ${typeof x}","messagePattern":"Cannot reverse (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"internal/engine/stdlib.js","lineNumber":146,"sourceCode":"}\n\nfunction zip(...x) {\n  const length = Math.min(...x.map(a => a.length))\n  const res = []\n  for (let i = 0; i < length; i++) {\n    res.push(x.map(a => a[i]))\n  }\n  return res\n}\n\nfunction flatten(x) {\n  if (Array.isArray(x)) return x.flat()\n  throw new Error(`Cannot flatten ${typeof x}`)\n}\n\nfunction reverse(x) {\n  if (Array.isArray(x)) return x.reverse()\n  throw new Error(`Cannot reverse ${typeof x}`)\n}\n\nfunction keys(x) {\n  if (typeof x === 'object' && x !== null) return Object.keys(x)\n  throw new Error(`Cannot get keys of ${typeof x}`)\n}\n\nfunction values(x) {\n  if (typeof x === 'object' && x !== null) return Object.values(x)\n  throw new Error(`Cannot get values of ${typeof x}`)\n}\n\nfunction list(x) {\n  if (Array.isArray(x)) {\n    for (const y of x) console.log(y)\n    return skip\n  }\n  throw new Error(`Cannot list ${typeof x}`)","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/antonmedv/fx/blob/4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe/internal/engine/stdlib.js#L128-L164","documentation":"reverse(x) reverses an array in place and only accepts arrays; any other type throws 'Cannot reverse <type>'. Strings must be split into an array first, objects have no defined reversal, and null/undefined are rejected outright.","triggerScenarios":"reverse('abc'), reverse({a:1}), reverse(null), reverse(undefined), or reverse on a scalar that a pipeline produced instead of a list.","commonSituations":"Reversing a string (need split('')/reverse/join('')), reversing object key order (need Object.keys), or a lookup returning null on absent data.","solutions":["Check Array.isArray(x) before reversing","For strings: x.split('').reverse().join('')","For object key order: Object.keys(x).reverse()","Default nullable inputs: reverse(x ?? [])"],"exampleFix":"// before\nconst rev = reverse(name)\n// after\nconst rev = typeof name === 'string' ? name.split('').reverse().join('') : reverse(name ?? [])","handlingStrategy":"type-guard","validationCode":"if (!Array.isArray(x)) throw new TypeError('reverse() requires an array; got ' + (x === null ? 'null' : typeof x))","typeGuard":"function isReversible(x) { return Array.isArray(x) }","tryCatchPattern":"let rev; try { rev = reverse(x) } catch (e) { if (e.message.startsWith('Cannot reverse')) { rev = [] } else { throw e } }","preventionTips":["Reverse strings via split('').reverse().join('')","Reverse object keys via Object.keys(x).reverse()","Coerce nullables: reverse(x ?? [])","Note reverse() mutates in place — copy first if the original matters"],"tags":["type-error","runtime","stdlib"],"backgroundTag":"invalid-argument-value","analyzedSha":"4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe","analyzedAt":"2026-09-02T02:17:47.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}