{"id":"a9e5456a5222c736","repo":"colinhacks/zod","slug":"unrecognized-hash-format-format","errorCode":null,"errorMessage":"Unrecognized hash format: ${format}","messagePattern":"Unrecognized hash format: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/zod/src/v4/classic/schemas.ts","lineNumber":1022,"sourceCode":"\nexport function hostname(_params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<\"hostname\"> {\n  return core._stringFormat(ZodCustomStringFormat, \"hostname\", core.regexes.hostname, _params) as any;\n}\n\nexport function hex(_params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<\"hex\"> {\n  return core._stringFormat(ZodCustomStringFormat, \"hex\", core.regexes.hex, _params) as any;\n}\n\nexport function hash<Alg extends util.HashAlgorithm, Enc extends util.HashEncoding = \"hex\">(\n  alg: Alg,\n  params?: {\n    enc?: Enc;\n  } & core.$ZodStringFormatParams\n): ZodCustomStringFormat<`${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  if (!regex) throw new Error(`Unrecognized hash format: ${format}`);\n  return core._stringFormat(ZodCustomStringFormat, format, regex, params) as any;\n}\n\n// ZodNumber\nexport interface _ZodNumber<Internals extends core.$ZodNumberInternals = core.$ZodNumberInternals>\n  extends _ZodType<Internals> {\n  gt(value: number, params?: string | core.$ZodCheckGreaterThanParams): this;\n  /** Identical to .min() */\n  gte(value: number, params?: string | core.$ZodCheckGreaterThanParams): this;\n  min(value: number, params?: string | core.$ZodCheckGreaterThanParams): this;\n  lt(value: number, params?: string | core.$ZodCheckLessThanParams): this;\n  /** Identical to .max() */\n  lte(value: number, params?: string | core.$ZodCheckLessThanParams): this;\n  max(value: number, params?: string | core.$ZodCheckLessThanParams): this;\n  /** Consider `z.int()` instead. This API is considered *legacy*; it will never be removed but a better alternative exists. */\n  int(params?: string | core.$ZodCheckNumberFormatParams): this;\n  /** @deprecated This is now identical to `.int()`. Only numbers in the safe integer range are accepted. */\n  safe(params?: string | core.$ZodCheckNumberFormatParams): this;","sourceCodeStart":1004,"sourceCodeEnd":1040,"githubUrl":"https://github.com/colinhacks/zod/blob/912f0f51b0ced654d0069741e7160834dca742ee/packages/zod/src/v4/classic/schemas.ts#L1004-L1040","documentation":"Thrown by z.hash(alg, { enc }) in the v4 classic API when the assembled format string `${alg}_${enc}` does not map to a known entry in core.regexes. At the type level Alg and Enc are constrained, but the runtime lookup guards against arbitrary string casts or future registry mismatches.","triggerScenarios":"Calling `z.hash('sha3' as any)` with an algorithm outside the supported set (md5, sha1, sha256, sha384, sha512), or `z.hash('sha256', { enc: 'ascii' as any })` with an encoding other than hex/base64/base64url.","commonSituations":"Casting string literals with `as any` to bypass the type guard; user-driven algorithm selection feeding an unsupported value; code targeting a hash family zod does not bundle a regex for.","solutions":["Use one of the supported algorithms: md5, sha1, sha256, sha384, or sha512.","Use a supported encoding: hex (default), base64, or base64url.","For an unsupported format, build a custom string format with z.string().refine() / z4.stringFormat() and your own regex."],"exampleFix":"// before\nz.hash('sha3' as any);\nz.hash('sha256', { enc: 'ascii' as any });\n\n// after\nz.hash('sha256');\nz.hash('sha512', { enc: 'base64url' });","handlingStrategy":"type-guard","validationCode":"const ALGS = new Set([\"md5\",\"sha1\",\"sha256\",\"sha384\",\"sha512\"]);\nconst ENCS = new Set([\"hex\",\"base64\",\"base64url\"]);\nfunction assertHashParams(alg: string, enc = \"hex\") {\n  if (!ALGS.has(alg)) throw new Error(`Unsupported hash algorithm: ${alg}`);\n  if (!ENCS.has(enc)) throw new Error(`Unsupported hash encoding: ${enc}`);\n}","typeGuard":"function isSupportedAlg(a: string): a is \"md5\"|\"sha1\"|\"sha256\"|\"sha384\"|\"sha512\" {\n  return [\"md5\",\"sha1\",\"sha256\",\"sha384\",\"sha512\"].includes(a);\n}\nfunction isSupportedEnc(e: string): e is \"hex\"|\"base64\"|\"base64url\" {\n  return [\"hex\",\"base64\",\"base64url\"].includes(e);\n}","tryCatchPattern":null,"preventionTips":["Constrain user input for hash algorithm/encoding with an allow-list enum.","Avoid `as any` casts when calling z.hash — let the type system catch mistakes.","For unsupported hashes, register a custom string format with your own regex."],"tags":["hash","string-format","v4","schemas"],"analyzedSha":"912f0f51b0ced654d0069741e7160834dca742ee","analyzedAt":"2026-08-03T17:41:55.908Z","schemaVersion":2}