{"id":"ea8f65f8542e36fc","repo":"vitest-dev/vitest","slug":"no-codec-found-for-type-type","errorCode":null,"errorMessage":"No codec found for type ${type}","messagePattern":"No codec found for type (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser/src/node/commands/screenshotMatcher/codecs/index.ts","lineNumber":11,"sourceCode":"import png from './png'\n\nexport function getCodec(type: 'png'): typeof png\n\nexport function getCodec(type: string) {\n  switch (type) {\n    case 'png':\n      return png\n\n    default:\n      throw new Error(`No codec found for type ${type}`)\n  }\n}\n\nexport type AnyCodec = typeof png\n","sourceCodeStart":1,"sourceCodeEnd":16,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/browser/src/node/commands/screenshotMatcher/codecs/index.ts#L1-L16","documentation":"Thrown by `getCodec` at codecs/index.ts:10-11 when the requested image type is not 'png' — the only built-in codec. The screenshot matcher decodes reference images and encodes diffs using a codec keyed by image type; an unsupported type means decoding/encoding cannot proceed.","triggerScenarios":"Configuring `toMatchScreenshot` options to use an image type other than 'png' (e.g. 'jpeg', 'webp'). A reference baseline file in a format other than PNG. A custom codec that wasn't registered.","commonSituations":"Users wanting JPEG/WebP baselines without registering a codec. Tooling that produces screenshots in a default format the host browser uses. Misreading the type option as a quality/format string.","solutions":["Use the supported 'png' type for screenshots/baselines.","Convert existing baselines to PNG before pointing the matcher at them.","If you need another format, contribute/register a codec in the registry (extend the `Codec` interface)."],"exampleFix":"// before\nexpect(page).toMatchScreenshot({ /* options.imageType: 'jpeg' */ })\n\n// after\nexpect(page).toMatchScreenshot({ /* use default PNG */ })","handlingStrategy":"validation","validationCode":"function isSupportedImageType(t: string): t is 'png' {\n  return t === 'png'\n}\nif (!isSupportedImageType(imageType)) throw new Error('only png is supported')","typeGuard":"function isPng(t: string): t is 'png' {\n  return t === 'png'\n}","tryCatchPattern":null,"preventionTips":["Use PNG for screenshots and baselines.","Convert existing baselines to PNG before pointing the matcher at them.","Register a custom codec if you genuinely need another format."],"tags":["browser","screenshot","codec","image","tomatchscreenshot","configuration"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}