{"record":{"id":"80671c44dfc3357a","repo":"vitest-dev/vitest","slug":"unknown-mock-type-event-as-any-type","errorCode":null,"errorMessage":"Unknown mock type: ${(event as any).type}","messagePattern":"Unknown mock type: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mocker/src/registry.ts","lineNumber":90,"sourceCode":"        const module = AutomockedModule.fromJSON(event)\n        this.add(module)\n        return module\n      }\n      else if (event.type === 'autospy') {\n        const module = AutospiedModule.fromJSON(event)\n        this.add(module)\n        return module\n      }\n      else if (event.type === 'redirect') {\n        const module = RedirectedModule.fromJSON(event)\n        this.add(module)\n        return module\n      }\n      else if (event.type === 'manual') {\n        throw new Error(`Cannot set serialized manual mock. Define a factory function manually with \\`ManualMockedModule.fromJSON()\\`.`)\n      }\n      else {\n        throw new Error(`Unknown mock type: ${(event as any).type}`)\n      }\n    }\n\n    if (typeof raw !== 'string') {\n      throw new TypeError('[vitest] Mocks require a raw string.')\n    }\n\n    if (typeof url !== 'string') {\n      throw new TypeError('[vitest] Mocks require a url string.')\n    }\n\n    if (typeof id !== 'string') {\n      throw new TypeError('[vitest] Mocks require an id string.')\n    }\n\n    if (type === 'manual') {\n      if (typeof factoryOrRedirect !== 'function') {\n        throw new TypeError('[vitest] Manual mocks require a factory function.')","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/mocker/src/registry.ts#L72-L108","documentation":"Thrown by `MockerRegistry.register` (object-form) when `event.type` is none of `'automock'`, `'autospy'`, `'redirect'`, `'manual'`. This is a defensive guard indicating the event object's `type` field is outside the known `MockedModuleType` union. Under correct usage the type is exhaustively checked; reaching the `else` means a corrupted, version-mismatched, or hand-crafted event was passed.","triggerScenarios":"Passing an object with an unrecognized `type` string to `register`; an RPC/IPC payload whose `type` field does not match any version of the `MockedModuleSerialized` union (e.g., a future type from a newer Vitest running against an older registry).","commonSituations":"Version skew between the Vitest node-side runner and the browser-side mocker; a custom transport injecting non-standard events; a corrupted or hand-built registry payload.","solutions":["Ensure the node-side and browser-side Vitest builds are the same version.","If extending the type system, add the new type branch to `register` and to the `MockedModuleType` union.","Validate the event `type` against the known union before calling `register`."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// Validate event.type against the known union before registering.\nconst KNOWN_TYPES = new Set(['automock', 'autospy', 'manual', 'redirect'])\nif (!KNOWN_TYPES.has(event.type)) {\n  throw new Error(`Unknown mock type in event: ${event.type}`)\n}\nregistry.register(event)","typeGuard":"function isKnownMockedModuleSerialized(event: unknown): event is { type: 'automock' | 'autospy' | 'manual' | 'redirect' } {\n  return typeof event === 'object' && event !== null\n    && typeof (event as any).type === 'string'\n    && ['automock', 'autospy', 'manual', 'redirect'].includes((event as any).type)\n}","tryCatchPattern":null,"preventionTips":["Keep node-side and browser-side mocker builds on the same version.","Add a version handshake to the RPC layer so mismatched type sets fail fast.","Validate event payloads at the transport boundary before they reach the registry."],"tags":["registry","mock-registry","internal-guard","version-skew"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}