{"record":{"id":"dea961584c774f63","repo":"antonmedv/fx","slug":"cannot-get-unique-values-of-typeof-x","errorCode":null,"errorMessage":"Cannot get unique values of ${typeof x}","messagePattern":"Cannot get unique values of (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"internal/engine/stdlib.js","lineNumber":35,"sourceCode":"}\n\nconst skip = Symbol('skip')\n\nfunction apply(fn, ...args) {\n  if (typeof fn === 'function') return fn(...args)\n  return fn\n}\n\nfunction len(x) {\n  if (Array.isArray(x)) return x.length\n  if (typeof x === 'string') return x.length\n  if (typeof x === 'object' && x !== null) return Object.keys(x).length\n  throw new Error(`Cannot get length of ${typeof x}`)\n}\n\nfunction uniq(x) {\n  if (Array.isArray(x)) return [...new Set(x)]\n  throw new Error(`Cannot get unique values of ${typeof x}`)\n}\n\nfunction sort(x) {\n  if (Array.isArray(x)) return x.sort()\n  throw new Error(`Cannot sort ${typeof x}`)\n}\n\nfunction isFalsely(x) {\n  return x === false || x === null || x === undefined\n}\n\nfunction filter(fn) {\n  return function (x) {\n    if (Array.isArray(x)) {\n      return x.filter((v, i) => !isFalsely(fn(v, i)))\n    }\n    return isFalsely(fn(x)) ? skip : x\n  }","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/antonmedv/fx/blob/4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe/internal/engine/stdlib.js#L17-L53","documentation":"uniq(x) deduplicates array elements via a Set and only accepts arrays. Passing anything else — string, object, number, null, undefined — falls through to `throw new Error('Cannot get unique values of <type>')`. Note it does not even accept strings, so 'aab' must be split into characters first.","triggerScenarios":"uniq('aabb'), uniq({a:1}), uniq(null), uniq(undefined), or uniq on the result of a function that returned a non-array (e.g. a lookup that yielded an object or null).","commonSituations":"Feeding uniq a comma-separated string instead of a split array, passing a JSON object where an array of records was expected, or null from an absent config/env value.","solutions":["Ensure the input is an array; convert first with Array.from(x) or x.split(',') for strings","Default null/undefined to an empty array: uniq(x ?? [])","For strings, split into characters/items before deduplicating","Guard the call site with Array.isArray before invoking uniq"],"exampleFix":"// before\nconst names = uniq(rawNames)\n// after\nconst names = uniq(Array.isArray(rawNames) ? rawNames : String(rawNames ?? '').split(','))","handlingStrategy":"type-guard","validationCode":"if (!Array.isArray(x)) throw new TypeError('uniq() requires an array; got ' + (x === null ? 'null' : typeof x))","typeGuard":"function isArrayForUniq(x) { return Array.isArray(x) }","tryCatchPattern":"let out; try { out = uniq(x) } catch (e) { if (e.message.startsWith('Cannot get unique values of')) { out = [] } else { throw e } }","preventionTips":["Split strings before deduplicating: x.split(',')","Coerce lookups: uniq(x ?? [])","Keep data as arrays end-to-end in pipelines","Type-check inputs at module boundaries"],"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"}