{"record":{"id":"49dbd41e215a2f03","repo":"antonmedv/fx","slug":"cannot-delete-key-from-typeof-x","errorCode":null,"errorMessage":"Cannot delete key from ${typeof x}","messagePattern":"Cannot delete key from (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"internal/engine/stdlib.js","lineNumber":179,"sourceCode":"    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\nfunction exit(code) {\n  __exit__(code)\n}\n\nfunction save(x) {\n  if (typeof x === 'undefined') throw new Error('Cannot save undefined')\n  __save__(__stringify__(x, null, 2))\n  return x\n}\n\nfunction toBase64(x) {\n  return __toBase64__(x)\n}\n\nfunction fromBase64(x) {","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/antonmedv/fx/blob/4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe/internal/engine/stdlib.js#L161-L197","documentation":"del(key) is curried: del(key)(x) returns a copy of x with the key removed — splicing index `key` for arrays, or delete copy[key] for plain objects. The inner throw 'Cannot delete key from <type>' fires when x is neither an array nor a non-null object (string, number, boolean, null, undefined).","triggerScenarios":"del('password')(null), del(0)('abc'), del('k')(42), del('k')(undefined) — applying the returned deleter to a primitive; often the record being cleaned was null because the lookup failed.","commonSituations":"Sanitizing config/API payloads where an expected nested object is missing (null), redacting secrets from a record that turned out to be a scalar, or a pipeline stage that already unwrapped the object.","solutions":["Coerce null to an empty object before deleting: del(key)(x ?? {})","Verify the target is an object (typeof x === 'object' && x !== null) before applying","If a nested path may be absent, guard the whole expression: x?.user ?? {}","Try/catch when input shape is dynamic"],"exampleFix":"// before\nconst safe = del('password')(record)\n// after\nconst safe = del('password')(record ?? {})","handlingStrategy":"fallback","validationCode":"const target = del(key); if (x == null || (typeof x !== 'object' && !Array.isArray(x))) throw new TypeError('del() target must be an array or object; got ' + (x === null ? 'null' : typeof x))","typeGuard":"function isDeletable(x) { return Array.isArray(x) || (x !== null && typeof x === 'object') }","tryCatchPattern":"let out; try { out = del(key)(x) } catch (e) { if (e.message.startsWith('Cannot delete key from')) { out = x } else { throw e } }","preventionTips":["Coerce missing records: del(key)(x ?? {})","Guard nested paths: del('secret')(user?.profile ?? {})","Validate the record exists before sanitizing it","Keep del() applied at the object level, after lookups resolve"],"tags":["type-error","null","runtime","stdlib"],"backgroundTag":"null-or-undefined-input","analyzedSha":"4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe","analyzedAt":"2026-09-02T02:17:47.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}