{"record":{"id":"b2fd76b662ea8be8","repo":"Automattic/harper","slug":"assertion-failed","errorCode":null,"errorMessage":"Assertion failed","messagePattern":"Assertion failed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/harper.js/src/utils.ts","lineNumber":3,"sourceCode":"export function assert(condition: unknown, message?: string): asserts condition {\n\tif (!condition) {\n\t\tthrow new Error(message ?? 'Assertion failed');\n\t}\n}\n","sourceCodeStart":1,"sourceCodeEnd":6,"githubUrl":"https://github.com/Automattic/harper/blob/5fe7d5ab76492d83f3ecdbc3f1da83c75dcb6f83/packages/harper.js/src/utils.ts#L1-L6","documentation":"utils.assert(condition, message?) throws Error(message ?? 'Assertion failed') when the condition is falsy. When a caller (e.g. deserializeArg validating that a parsed 'Array'-tagged payload is really an array) omits a message, you get the bare 'Assertion failed'. It signals an internal invariant violation in the serializer's wire format rather than a user-facing input problem.","triggerScenarios":"Receiving a RequestArg whose type is 'Array' but whose json parses to a non-array (corrupted/hand-edited message, version-skewed serializer on the other side); any other assert() call site failing without a message.","commonSituations":"Mixing harper.js versions between main thread and worker; tampering with SerializedRequest payloads; a custom proxy/relay altering message JSON in transit.","solutions":["Ensure both sides of the worker channel run the same harper.js version (rebuild, bust caches)","Inspect the failing RequestArg: confirm type 'Array' payloads JSON-parse to arrays","Stop mutating or hand-generating serialized messages; use the public API","If it persists, capture the payload and file a bug — this indicates a serializer invariant break"],"exampleFix":"// before\nworker.postMessage(editedRequest); // payload shape no longer matches type tag\n// after\nawait linter.lint(text); // let the Serializer build the wire format","handlingStrategy":"try-catch","validationCode":"function isValidArrayArg(a: RequestArg) {\n  return a.type !== 'Array' || Array.isArray(JSON.parse(a.json));\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await linter.lint(text);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Assertion failed') {\n    console.error('Serializer invariant violated; recreate worker with matching harper.js version.');\n    linter.dispose();\n    linter = createLinter();\n  }\n  throw e;\n}","preventionTips":["Keep harper.js versions identical on both sides of the worker channel","Never mutate or hand-generate serialized messages","Recreate the WorkerLinter (fresh worker) after any assertion failure"],"tags":["assertion","serialization","internal-invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"5fe7d5ab76492d83f3ecdbc3f1da83c75dcb6f83","analyzedAt":"2026-09-06T11:34:38.610Z","contentChangedAt":"2026-09-06T11:34:38.610Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}