{"record":{"id":"1e7f09c79f920042","repo":"immutable-js/immutable-js","slug":"error","errorCode":null,"errorMessage":"{}","messagePattern":"\\{\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/utils/invariant.ts","lineNumber":5,"sourceCode":"export default function invariant(\n  condition: unknown,\n  error: string\n): asserts condition {\n  if (!condition) throw new Error(error);\n}\n","sourceCodeStart":1,"sourceCodeEnd":7,"githubUrl":"https://github.com/immutable-js/immutable-js/blob/59fdaae67606ceedee7902a44703c893949f673b/src/utils/invariant.ts#L1-L7","documentation":"This error comes from the internal invariant() assertion helper: when the condition passed to it is falsy, it throws an Error with the supplied message. It guards preconditions across the library — the listed call sites are get, a constructor, setProp, and assertNotfinite — e.g. asserting that get() received a valid search value, that an index/count is not Infinity, and that internal object shapes are consistent. Seeing this error means an API was called with arguments that violate a documented precondition (or an internal state assumption was broken by misuse or a version mismatch).","triggerScenarios":"Calling collection.get() / .has() with no argument or an invalid key when an assertion requires a searchValue; constructing an Indexed Iterable or Range with infinite/NaN bounds that fail assertNotInfinite; setProp hitting an inconsistent internal record shape; mixing Immutable versions where internal symbols/flags checked in constructors differ, making the invariant condition falsy.","commonSituations":"Passing undefined to get() because a variable was never initialized (missing env var or missing config field); duplicated/peer-conflicting immutable packages in node_modules (npm or yarn hoisting issues) after an upgrade, causing constructor invariants to fail; computing sizes/limits with Infinity or NaN from bad math; calling methods with arguments built from unvalidated external input.","solutions":["Inspect the stack to identify which call site (get, constructor, setProp, assertNotInfinite) failed and validate that exact argument before the call","Ensure get()/has() receive an actual key: state.get('key') not state.get(maybeUndefined)","If it involves assertNotInfinite, fix the arithmetic producing Infinity/NaN in sizes, indices, or Range bounds","Run npm ls immutable (or yarn why immutable) and dedupe to a single version — mixed versions commonly break internal constructor invariants","Upgrade the library to a consistent patched version if the invariant fires on a known-buggy release"],"exampleFix":"// before\nconst id = req.query.id; // may be undefined\nconst item = map.get(id); // invariant can fail\n\n// after\nconst id = req.query.id;\nconst item = id != null ? map.get(id) : undefined;","handlingStrategy":"validation","validationCode":"const key = possiblyMissing;\nconst value = key !== undefined && key !== null ? map.get(key) : undefined;\n\n// for numeric bounds:\nconst size = Number.isFinite(n) ? n : 0; // avoid Infinity reaching assertNotInfinite","typeGuard":"function isFiniteIndex(n: unknown): n is number {\n  return typeof n === 'number' && Number.isFinite(n);\n}","tryCatchPattern":"try {\n  value = map.get(key);\n} catch (e) {\n  if (e instanceof Error && /assertNotInfinite|Cannot get/.test(e.message)) {\n    value = undefined; // recover from bad input\n  } else throw e;\n}","preventionTips":["Always check arguments for undefined/null before calling get/has","Run npm ls immutable to ensure a single version across the dependency tree","Sanitize numeric sizes/indices with Number.isFinite before building collections","Pin a known-good library version in package.json and lockfile"],"tags":["immutable","invariant","assertion","precondition","argument-validation","version-conflict"],"backgroundTag":"assertion-precondition-failed","analyzedSha":"59fdaae67606ceedee7902a44703c893949f673b","analyzedAt":"2026-08-27T20:14:53.132Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}