denoland/deno · critical · Error

Unknown worker event: "${type}"

Error message

Unknown worker event: "${type}"

What it means

The worker-host control protocol defines exactly three event types (1 = TerminalError, 2 = Error, 3 = Close); the poll loop's default branch in runtime/js/11_workers.js throws `Unknown worker event: "${type}"` for anything else. This is an internal invariant guard, reachable only when the Rust binary and the JavaScript runtime snapshot disagree on the protocol, or when embedder code injects malformed control messages through core ops. It is not caused by user-level worker code.

Source

Thrown at runtime/js/11_workers.js:244

      }

      switch (type) {
        case 1: { // TerminalError
          this.#status = "CLOSED";
        } /* falls through */
        case 2: { // Error
          if (!this.#handleError(data)) {
            throw new Error("Unhandled error in child worker.");
          }
          break;
        }
        case 3: { // Close
          log(`Host got "close" message from worker: ${this.#name}`);
          this.#status = "CLOSED";
          return;
        }
        default: {
          throw new Error(`Unknown worker event: "${type}"`);
        }
      }
    }
  };

  #dispatchWorkerMessage(data) {
    let message, transferables;
    try {
      const v = deserializeJsMessageData(data);
      message = v[0];
      transferables = v[1];
    } catch (err) {
      const event = new MessageEvent("messageerror", {
        cancelable: false,
        data: err,
      });
      setIsTrusted(event, true);
      this.dispatchEvent(event);

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Reinstall or rebuild Deno so the binary and its runtime snapshot come from the same commit (remove target/, clear DENO_DIR caches on custom setups)
  2. If embedding deno_core, never synthesize control-channel messages; use the public worker APIs
  3. Report upstream if it reproduces on a clean official binary — it indicates a protocol regression
Defensive patterns

Strategy: fallback

Try / catch

globalThis.addEventListener('unhandledrejection', (e) => {
  if (String(e.reason).includes('Unknown worker event')) {
    console.error('deno binary/runtime snapshot mismatch — reinstall Deno');
    Deno.exit(1);
  }
});

Prevention

When it happens

Trigger: A deno binary running against a mismatched or patched generated runtime JS (custom builds, stale artifacts after an interrupted upgrade); a custom deno_core embedder calling the control-channel ops directly; a corrupted snapshot cache.

Common situations: Mixed-version installs (binary from one release, cached snapshot/CLI artifacts from another); building deno from source with stale target/ artifacts after pulling new commits; heavily customized embedder setups.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/e343caf96e6dac1a. Report an issue: GitHub.