{"id":"75f46f7c36be1650","repo":"colinhacks/zod","slug":"unrecognized-hash-format-format-75f46f","errorCode":null,"errorMessage":"Unrecognized hash format: ${format}","messagePattern":"Unrecognized hash format: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/zod/src/v4/mini/schemas.ts","lineNumber":535,"sourceCode":"}\n\n// @__NO_SIDE_EFFECTS__\nexport function hex(_params?: string | core.$ZodStringFormatParams): ZodMiniCustomStringFormat<\"hex\"> {\n  return core._stringFormat(ZodMiniCustomStringFormat, \"hex\", core.regexes.hex, _params) as any;\n}\n\n// @__NO_SIDE_EFFECTS__\nexport function hash<Alg extends util.HashAlgorithm, Enc extends util.HashEncoding = \"hex\">(\n  alg: Alg,\n  params?: {\n    enc?: Enc;\n  } & core.$ZodStringFormatParams\n): ZodMiniCustomStringFormat<`${Alg}_${Enc}`> {\n  const enc = params?.enc ?? \"hex\";\n  const format = `${alg}_${enc}` as const;\n  const regex = core.regexes[format as keyof typeof core.regexes] as RegExp;\n  // check for unrecognized format\n  if (!regex) throw new Error(`Unrecognized hash format: ${format}`);\n  return core._stringFormat(ZodMiniCustomStringFormat, format, regex, params) as any;\n}\n\n// ZodMiniNumber\ninterface _ZodMiniNumber<T extends core.$ZodNumberInternals<unknown> = core.$ZodNumberInternals<unknown>>\n  extends _ZodMiniType<T>,\n    core.$ZodNumber<T[\"input\"]> {\n  _zod: T;\n}\nexport interface ZodMiniNumber<Input = unknown>\n  extends _ZodMiniNumber<core.$ZodNumberInternals<Input>>,\n    core.$ZodNumber<Input> {}\nexport const ZodMiniNumber: core.$constructor<ZodMiniNumber> = /*@__PURE__*/ core.$constructor(\n  \"ZodMiniNumber\",\n  (inst, def) => {\n    core.$ZodNumber.init(inst, def);\n    ZodMiniType.init(inst, def);\n  }","sourceCodeStart":517,"sourceCodeEnd":553,"githubUrl":"https://github.com/colinhacks/zod/blob/912f0f51b0ced654d0069741e7160834dca742ee/packages/zod/src/v4/mini/schemas.ts#L517-L553","documentation":"Thrown by the mini `hash()` schema factory (mini/schemas.ts:535) when the composed `${alg}_${enc}` format string (e.g. `sha256_base64`) does not resolve to a known entry in `core.regexes`. The supported algorithms are md5/sha1/sha256/sha384/sha512 and encodings hex/base64/base64url; any other combination — or any of those that lacks a prebuilt regex — fails immediately.","triggerScenarios":"Calling `z.hash('md5', { enc: 'utf8' })`, `z.hash('sha3', { enc: 'hex' })`, or any combination where `core.regexes` does not contain the `${alg}_${enc}` key. Also reachable if `params.enc` is set to an unsupported value.","commonSituations":"Asking for a hash algorithm not in the supported set (e.g. sha3-256, blake2b); asking for an encoding outside hex/base64/base64url; passing a typo'd algorithm string; version mismatch where a regex entry was removed.","solutions":["Use one of the supported algorithms: md5, sha1, sha256, sha384, sha512.","Use one of the supported encodings: hex, base64, base64url (default is hex).","For unsupported hashes, fall back to a custom string format: `z.string().check(...)` with your own regex or use `z.iso`/custom format if available."],"exampleFix":"// before\nconst H = z.hash('sha3', { enc: 'utf8' });\n\n// after\nconst H = z.hash('sha256', { enc: 'hex' });","handlingStrategy":"validation","validationCode":"const ALGS = ['md5','sha1','sha256','sha384','sha512'] as const;\nconst ENCS = ['hex','base64','base64url'] as const;\nfunction isHashCombo(a: string, e: string): boolean {\n  return (ALGS as readonly string[]).includes(a) && (ENCS as readonly string[]).includes(e);\n}\nif (!isHashCombo(alg, enc)) throw new Error('unsupported hash combo');\nconst H = z.hash(alg, { enc });","typeGuard":"type Alg = 'md5'|'sha1'|'sha256'|'sha384'|'sha512';\ntype Enc = 'hex'|'base64'|'base64url';\nfunction isAlg(x: string): x is Alg { return ['md5','sha1','sha256','sha384','sha512'].includes(x); }\nfunction isEnc(x: string): x is Enc { return ['hex','base64','base64url'].includes(x); }","tryCatchPattern":null,"preventionTips":["Constrain algorithm/encoding inputs to the supported literal unions at the type level.","For unsupported hashes (sha3, blake2b), build a custom string-format schema with your own regex."],"tags":["zod","mini","hash","validation"],"analyzedSha":"912f0f51b0ced654d0069741e7160834dca742ee","analyzedAt":"2026-08-03T17:41:55.908Z","schemaVersion":2}