{"record":{"id":"a7c8e256fcf3a766","repo":"Automattic/harper","slug":"unhandled-case-arg","errorCode":null,"errorMessage":"Unhandled case: ${arg}","messagePattern":"Unhandled case: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/harper.js/src/Serializer.ts","lineNumber":103,"sourceCode":"\t\t\tif (type === undefined) {\n\t\t\t\tthrow new Error('Unhandled case: type undefined');\n\t\t\t}\n\n\t\t\treturn { json, type };\n\t\t}\n\n\t\tif (argType == 'object') {\n\t\t\treturn {\n\t\t\t\tjson: JSON.stringify(\n\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\tObject.entries(arg).map(([key, value]) => this.serializeArg([key, value])),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t\ttype: 'object',\n\t\t\t};\n\t\t}\n\n\t\tthrow new Error(`Unhandled case: ${arg}`);\n\t}\n\n\tasync serialize(req: DeserializedRequest): Promise<SerializedRequest> {\n\t\treturn {\n\t\t\tprocName: req.procName,\n\t\t\targs: await Promise.all(req.args.map((arg) => this.serializeArg(arg))),\n\t\t};\n\t}\n\n\tasync deserializeArg(requestArg: RequestArg): Promise<any> {\n\t\tconst { Lint, Span, Suggestion } = await this.binary.getBinaryModule();\n\n\t\tswitch (requestArg.type) {\n\t\t\tcase 'bigint':\n\t\t\t\treturn BigInt(requestArg.json);\n\t\t\tcase 'undefined':\n\t\t\t\treturn undefined;\n\t\t\tcase 'boolean':","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/Automattic/harper/blob/5fe7d5ab76492d83f3ecdbc3f1da83c75dcb6f83/packages/harper.js/src/Serializer.ts#L85-L121","documentation":"serializeArg's final fallback: when an argument is not an Array, not string/number/boolean/undefined/bigint, has no to_json() method, and is not a plain object, the serializer has no way to represent it on the worker wire and throws 'Unhandled case: <arg>'. This rejects unsupported argument kinds (functions, symbols, Maps, Sets, class instances without to_json, etc.) at RPC time.","triggerScenarios":"Calling a WorkerLinter method (lint, isLikelyEnglish, applySuggestion, ...) with arguments like a function, Symbol, Map/Set, DOM node, or a class instance lacking to_json() — anything outside the SerializableTypes surface.","commonSituations":"Passing a Map<string, ...> where a plain object was expected; accidentally passing a callback or Promise into lint config arguments; passing typed arrays or Dates.","solutions":["Convert the argument to a supported type before the call: plain object, array, string, number, boolean, bigint, or undefined","Replace Map/Set with plain objects/arrays; convert Date to a number/string","Remove callbacks or non-serializable values from the arguments","If a needed type is missing, serialize it yourself (e.g. Array.from(map.entries())) or file an issue to extend Serializer"],"exampleFix":"// before\nawait linter.lint(text, [new Map([['a', 1]])]);\n// after\nawait linter.lint(text, [{ a: 1 }]);","handlingStrategy":"validation","validationCode":"function isRpcSerializable(v: unknown): boolean {\n  return v === undefined || ['string','number','boolean','bigint'].includes(typeof v)\n    || Array.isArray(v)\n    || (typeof v === 'object' && v !== null && (typeof (v as any).to_json === 'function'\n      || v.constructor?.name === 'Object'));\n}\nargs.every(isRpcSerializable) || console.error('unsupported WorkerLinter arg', args);","typeGuard":null,"tryCatchPattern":"try {\n  return await linter.lint(text);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Unhandled case:')) {\n    console.error('Unsupported argument passed to WorkerLinter; normalize inputs.');\n  }\n  throw e;\n}","preventionTips":["Convert Map/Set/Date to plain objects/arrays/primitives before calling linter methods","Never pass functions, Symbols, or DOM objects into WorkerLinter calls","Keep a typed wrapper around WorkerLinter so unsupported types are rejected at compile time"],"tags":["serialization","worker","unsupported-type"],"backgroundTag":"unsupported-operation","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"}