antonmedv/fx · error · Error
Cannot list ${typeof x}
Error message
Cannot list ${typeof x} What it means
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.
Source
Thrown at internal/engine/stdlib.js:164
throw new Error(`Cannot reverse ${typeof x}`)
}
function keys(x) {
if (typeof x === 'object' && x !== null) return Object.keys(x)
throw new Error(`Cannot get keys of ${typeof x}`)
}
function values(x) {
if (typeof x === 'object' && x !== null) return Object.values(x)
throw new Error(`Cannot get values of ${typeof x}`)
}
function list(x) {
if (Array.isArray(x)) {
for (const y of x) console.log(y)
return skip
}
throw new Error(`Cannot list ${typeof x}`)
}
function del(key) {
return function (x) {
if (Array.isArray(x)) {
const copy = [...x]
copy.splice(key, 1)
return copy
}
if (typeof x === 'object' && x !== null) {
const copy = {...x}
delete copy[key]
return copy
}
throw new Error(`Cannot delete key from ${typeof x}`)
}
}
View on GitHub (pinned to 4f31cd3a0c)
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
Example fix
// before list(result) // after list(Array.isArray(result) ? result : [result])
Defensive patterns
Strategy: type-guard
Validate before calling
if (!Array.isArray(x)) throw new TypeError('list() requires an array; got ' + (x === null ? 'null' : typeof x)) Type guard
function isListable(x) { return Array.isArray(x) } Try / catch
try { list(x) } catch (e) { if (e.message.startsWith('Cannot list')) { console.log([x]) } else { throw e } } Prevention
- 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
When it happens
Trigger: list({a:1}), list('abc'), list(null), list(undefined), list(42) — any non-array passed where an array of items to print was expected.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Cannot get length of ${typeof x}
- Cannot get unique values of ${typeof x}
- Cannot sort ${typeof x}
- Cannot flatten ${typeof x}
- Cannot reverse ${typeof x}
AI-assisted analysis of antonmedv/fx@4f31cd3a0c (2026-09-02).
Data as JSON: /api/errors/ddecdacd99b77839.
Report an issue: GitHub.