Automattic/harper · error · Error

Assertion failed

Error message

Assertion failed

What it means

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.

Source

Thrown at packages/harper.js/src/utils.ts:3

export function assert(condition: unknown, message?: string): asserts condition {
	if (!condition) {
		throw new Error(message ?? 'Assertion failed');
	}
}

View on GitHub (pinned to 5fe7d5ab76)

Solutions

  1. Ensure both sides of the worker channel run the same harper.js version (rebuild, bust caches)
  2. Inspect the failing RequestArg: confirm type 'Array' payloads JSON-parse to arrays
  3. Stop mutating or hand-generating serialized messages; use the public API
  4. If it persists, capture the payload and file a bug — this indicates a serializer invariant break

Example fix

// before
worker.postMessage(editedRequest); // payload shape no longer matches type tag
// after
await linter.lint(text); // let the Serializer build the wire format
Defensive patterns

Strategy: try-catch

Validate before calling

function isValidArrayArg(a: RequestArg) {
  return a.type !== 'Array' || Array.isArray(JSON.parse(a.json));
}

Try / catch

try {
  return await linter.lint(text);
} catch (e) {
  if (e instanceof Error && e.message === 'Assertion failed') {
    console.error('Serializer invariant violated; recreate worker with matching harper.js version.');
    linter.dispose();
    linter = createLinter();
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Mixing harper.js versions between main thread and worker; tampering with SerializedRequest payloads; a custom proxy/relay altering message JSON in transit.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of Automattic/harper@5fe7d5ab76 (2026-09-06). Data as JSON: /api/errors/b2fd76b662ea8be8. Report an issue: GitHub.