{"record":{"id":"ddecdacd99b77839","repo":"antonmedv/fx","slug":"cannot-list-typeof-x","errorCode":null,"errorMessage":"Cannot list ${typeof x}","messagePattern":"Cannot list (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"internal/engine/stdlib.js","lineNumber":164,"sourceCode":"  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}`)\n}\n\nfunction del(key) {\n  return function (x) {\n    if (Array.isArray(x)) {\n      const copy = [...x]\n      copy.splice(key, 1)\n      return copy\n    }\n    if (typeof x === 'object' && x !== null) {\n      const copy = {...x}\n      delete copy[key]\n      return copy\n    }\n    throw new Error(`Cannot delete key from ${typeof x}`)\n  }\n}\n","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/antonmedv/fx/blob/4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe/internal/engine/stdlib.js#L146-L182","documentation":"list(x) prints each element of an array to the console and returns the internal skip symbol; for any non-array it throws 'Cannot list <type>'. It is a display helper, so it deliberately rejects objects/strings instead of iterating their properties.","triggerScenarios":"list({a:1}), list('abc'), list(null), list(undefined), list(42) — any non-array passed where an array of items to print was expected.","commonSituations":"Logging results of a function that returned a single object instead of an array, listing entries of a config object (use Object.entries), or null from a failed fetch.","solutions":["Ensure the input is an array; wrap scalars: list([x])","For objects, list the entries: Object.entries(x) mapped to strings first","Default nullable values: list(x ?? [])","Guard with Array.isArray before calling list"],"exampleFix":"// before\nlist(result)\n// after\nlist(Array.isArray(result) ? result : [result])","handlingStrategy":"type-guard","validationCode":"if (!Array.isArray(x)) throw new TypeError('list() requires an array; got ' + (x === null ? 'null' : typeof x))","typeGuard":"function isListable(x) { return Array.isArray(x) }","tryCatchPattern":"try { list(x) } catch (e) { if (e.message.startsWith('Cannot list')) { console.log([x]) } else { throw e } }","preventionTips":["Wrap scalars before listing: list([x])","Use Object.entries for objects you want to display","Coerce nullables: list(x ?? [])","Remember list() returns the skip symbol — don't use its return value as data"],"tags":["type-error","runtime","logging","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"}