{"record":{"id":"0449a059a983d8a8","repo":"Automattic/harper","slug":"unhandled-case-requestarg-type","errorCode":null,"errorMessage":"Unhandled case: ${requestArg.type}","messagePattern":"Unhandled case: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/harper.js/src/Serializer.ts","lineNumber":143,"sourceCode":"\t\t\tcase 'Suggestion':\n\t\t\t\treturn Suggestion.from_json(requestArg.json);\n\t\t\tcase 'Lint':\n\t\t\t\treturn Lint.from_json(requestArg.json);\n\t\t\tcase 'Span':\n\t\t\t\treturn Span.from_json(requestArg.json);\n\t\t\tcase 'Array': {\n\t\t\t\tconst parsed = JSON.parse(requestArg.json);\n\t\t\t\tassert(Array.isArray(parsed));\n\t\t\t\treturn await Promise.all(parsed.map((arg) => this.deserializeArg(arg)));\n\t\t\t}\n\t\t\tcase 'object': {\n\t\t\t\tconst parsed = JSON.parse(requestArg.json);\n\t\t\t\treturn Object.fromEntries(\n\t\t\t\t\tawait Promise.all(parsed.map((val: any) => this.deserializeArg(val))),\n\t\t\t\t);\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unhandled case: ${requestArg.type}`);\n\t\t}\n\t}\n\n\tasync deserialize(request: SerializedRequest): Promise<DeserializedRequest> {\n\t\treturn {\n\t\t\tprocName: request.procName,\n\t\t\targs: await Promise.all(request.args.map((arg) => this.deserializeArg(arg))),\n\t\t};\n\t}\n}\n","sourceCodeStart":125,"sourceCodeEnd":154,"githubUrl":"https://github.com/Automattic/harper/blob/5fe7d5ab76492d83f3ecdbc3f1da83c75dcb6f83/packages/harper.js/src/Serializer.ts#L125-L154","documentation":"deserializeArg (worker side) switches on the wire tag (RequestArg.type) sent by the main thread. If the tag is not one of the known SerializableTypes — typically because main and worker threads run mismatched harper.js versions or a corrupted/hand-crafted message was posted — the switch falls through to default and throws 'Unhandled case: <type>'.","triggerScenarios":"A SerializedRequest or nested array/object element arrives with a type tag the worker's Serializer doesn't know (e.g. 'Date', 'Map', or a tag added in a newer harper.js running against an older worker build); manually posting messages to the worker; corrupted postMessage payloads.","commonSituations":"Version skew between bundled main-thread harper.js and a cached/split worker chunk; custom code speaking the worker protocol directly; HMR/service-worker caches mixing old and new chunks.","solutions":["Rebuild and redeploy so main thread and worker bundle the same harper.js version (bust caches/service worker)","Check the offending type tag in the message and ensure it is one of the documented SerializableTypes","Stop hand-crafting or mutating SerializedRequest objects; use the public WorkerLinter API","Clear stale worker caches (service workers, HTTP cache) so old chunks don't mix with new"],"exampleFix":"// before (hand-built message)\nworker.postMessage({ procName: 'lint', args: [{ json: 'x', type: 'Date' }] });\n// after\nconst linter = new WorkerLinter();\nawait linter.lint('x');","handlingStrategy":"validation","validationCode":"const KNOWN_TYPES = ['string','number','boolean','object','Suggestion','Lint','Span','Array','undefined','bigint'];\nfunction isValidSerializedRequest(req: any): boolean {\n  return req?.args?.every((a: any) => KNOWN_TYPES.includes(a?.type)) ?? false;\n}\nisValidSerializedRequest(request) || console.error('unknown arg type in request');","typeGuard":"const KNOWN_TYPES = ['string','number','boolean','object','Suggestion','Lint','Span','Array','undefined','bigint'] as const;\nfunction isKnownRequestArg(a: unknown): a is RequestArg {\n  return !!a && typeof a === 'object' && KNOWN_TYPES.includes((a as any).type);\n}","tryCatchPattern":"try {\n  return await linter.lint(text);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Unhandled case:')) {\n    // version skew or corrupted message; recreate the worker\n    linter.dispose();\n    linter = new WorkerLinter({ binary: wasmUrl });\n  }\n  throw e;\n}","preventionTips":["Deploy main thread and worker bundles atomically; avoid mixed cached chunks","Never hand-craft SerializedRequest messages; use the public API","Bust service-worker/HTTP caches when upgrading harper.js"],"tags":["serialization","worker","version-skew"],"backgroundTag":"json-unmarshal-failed","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"}