{"record":{"id":"9eb1b119b5c3f069","repo":"vitest-dev/vitest","slug":"vitest-unknown-mock-type-type","errorCode":null,"errorMessage":"[vitest] Unknown mock type: ${type}","messagePattern":"\\[vitest\\] Unknown mock type: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mocker/src/registry.ts","lineNumber":130,"sourceCode":"      return mock\n    }\n    else if (type === 'automock' || type === 'autospy') {\n      const mock = type === 'automock'\n        ? new AutomockedModule(raw, id, url)\n        : new AutospiedModule(raw, id, url)\n      this.add(mock)\n      return mock\n    }\n    else if (type === 'redirect') {\n      if (typeof factoryOrRedirect !== 'string') {\n        throw new TypeError('[vitest] Redirect mocks require a redirect string.')\n      }\n      const mock = new RedirectedModule(raw, id, url, factoryOrRedirect)\n      this.add(mock)\n      return mock\n    }\n    else {\n      throw new Error(`[vitest] Unknown mock type: ${type}`)\n    }\n  }\n\n  public delete(id: string): void {\n    this.registryByUrl.delete(id)\n  }\n\n  public deleteById(id: string): void {\n    this.registryById.delete(id)\n  }\n\n  public get(id: string): MockedModule | undefined {\n    return this.registryByUrl.get(id)\n  }\n\n  public getById(id: string): MockedModule | undefined {\n    return this.registryById.get(id)\n  }","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/mocker/src/registry.ts#L112-L148","documentation":"Internal invariant: MockRegistry.register received a type that is not one of 'manual', 'automock', 'autospy', or 'redirect'. This is a defensive guard for the else-branch after all known types are handled and should not occur from public API usage.","triggerScenarios":"Directly invoking registry.register with a type string outside the allowed union; corrupted serialized mock events; misuse of the internal register API; a typo in the type field of a mock descriptor.","commonSituations":"Internal code or a plugin passing an invalid type; a serialized mock event with an unrecognized type field; version mismatch where a newer mock type is sent to an older registry.","solutions":[],"exampleFix":"// before\nregistry.register({ type: 'magic', raw, id, url }, factory)\n// after\nregistry.register({ type: 'manual', raw, id, url }, factory)","handlingStrategy":"validation","validationCode":"const KNOWN_TYPES = new Set(['manual', 'automock', 'autospy', 'redirect'])\nif (!KNOWN_TYPES.has(type)) {\n  throw new Error(`Unsupported mock type '${type}'. Expected one of: ${[...KNOWN_TYPES].join(', ')}`)\n}\nregistry.register({ type, raw, id, url }, factoryOrRedirect)","typeGuard":"function isMockType(v: unknown): v is 'manual'|'automock'|'autospy'|'redirect' { return typeof v === 'string' && new Set(['manual','automock','autospy','redirect']).has(v) }","tryCatchPattern":null,"preventionTips":["Constrain the type via TypeScript literal union at the call site","Validate serialized mock events before dispatching to register","Keep @vitest/mocker versions aligned across packages"],"tags":["vitest","mocker","internal","invariant"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}