{"record":{"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/2d90846af918af9602e088812d63a035d47cdbe4/packages/zod/src/v4/mini/schemas.ts#L517-L553","documentation":"Thrown by the mini `hash()` factory when the computed format string `${alg}_${enc}` has no matching regex in core.regexes. Only the cross-product of supported algorithms (md5, sha1, sha256, sha384, sha512) and encodings (hex, base64, base64url) is pre-registered (15 combos). A typo in either argument, or a casing/whitespace mismatch, yields an unrecognized format.","triggerScenarios":"Calling `z.hash('sha256', { enc: 'hexadecimal' })` (wrong encoding name), `z.hash('SHA256')` (wrong casing), `z.hash('sha224')` (unsupported algorithm), or `z.hash('sha256', { enc: 'ascii' })`. The format string is built and looked up in the regex table; a miss throws.","commonSituations":"Using an algorithm Zod does not pre-register (sha224, sha3-*, blake2, ripemd); misspelling the encoding; passing uppercase from a config constant; assuming a wider algorithm set than is supported.","solutions":["Use one of the supported algorithms: md5, sha1, sha256, sha384, sha512.","Use one of the supported encodings: hex (default), base64, base64url — match the lowercase spelling exactly.","For an unsupported algorithm, register a custom string format with `z.stringFormat('sha224_hex', /your-regex/)` instead of the `hash()` helper."],"exampleFix":"// before\nz.hash('SHA256', { enc: 'hexadecimal' }); // throws: Unrecognized hash format: SHA256_hexadecimal\n\n// after\nz.hash('sha256', { enc: 'hex' });\n// or, for an unsupported algorithm, register a custom format:\nconst sha224Hex = z.stringFormat('sha224_hex', /^[0-9a-fA-F]{56}$/);","handlingStrategy":"validation","validationCode":"const HASH_ALGS = ['md5', 'sha1', 'sha256', 'sha384', 'sha512'] as const;\nconst HASH_ENCODINGS = ['hex', 'base64', 'base64url'] as const;\ntype HashAlg = (typeof HASH_ALGS)[number];\ntype HashEnc = (typeof HASH_ENCODINGS)[number];\nfunction assertHashFormat(alg: string, enc: string = 'hex'): void {\n  if (!(HASH_ALGS as readonly string[]).includes(alg)) {\n    throw new TypeError(`Unsupported hash algorithm: ${alg}. Supported: ${HASH_ALGS.join(', ')}`);\n  }\n  if (!(HASH_ENCODINGS as readonly string[]).includes(enc)) {\n    throw new TypeError(`Unsupported hash encoding: ${enc}. Supported: ${HASH_ENCODINGS.join(', ')}`);\n  }\n}\n// assertHashFormat(userAlg, userEnc); z.hash(userAlg as HashAlg, { enc: userEnc as HashEnc });","typeGuard":"function isSupportedHashFormat(alg: unknown, enc: unknown = 'hex'): boolean {\n  const a = ['md5', 'sha1', 'sha256', 'sha384', 'sha512'];\n  const e = ['hex', 'base64', 'base64url'];\n  return typeof alg === 'string' && typeof enc === 'string' && a.includes(alg) && e.includes(enc);\n}","tryCatchPattern":null,"preventionTips":["Lowercase and trim user-supplied algorithm/encoding before passing to `z.hash()`.","Validate alg/enc against the supported cross-product (5 algs x 3 encs) at the config boundary.","For unsupported algorithms, register a custom format with `z.stringFormat()` instead of forcing `z.hash()`."],"tags":["hash","string-format","api-misuse","validation","zod-v4","mini"],"backgroundTag":null,"analyzedSha":"2d90846af918af9602e088812d63a035d47cdbe4","analyzedAt":"2026-08-11T01:21:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-22T16:17:23.217Z"}