{"record":{"id":"19346185ca35c007","repo":"shadcn-ui/ui","slug":"invalid-preset-code-code","errorCode":null,"errorMessage":"Invalid preset code: ${code}","messagePattern":"Invalid preset code: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/shadcn/src/commands/preset.ts","lineNumber":43,"sourceCode":"}\n\ntype PresetDecodeResult = {\n  code: string\n  version: string\n  values: PresetValues\n  derived: string[]\n  url: string\n}\n\nexport function getPresetUrl(code: string) {\n  return `${SHADCN_URL}/create?preset=${code}`\n}\n\nexport function decodePresetCode(code: string): PresetDecodeResult {\n  const decoded = decodePreset(code)\n\n  if (!decoded) {\n    throw new Error(`Invalid preset code: ${code}`)\n  }\n\n  const derived: string[] = []\n  const chartColor = (decoded.chartColor ??\n    V1_CHART_COLOR_MAP[decoded.theme] ??\n    decoded.theme) as PresetValues[\"chartColor\"]\n\n  if (!decoded.chartColor) {\n    derived.push(\"chartColor\")\n  }\n\n  return {\n    code,\n    version: code[0],\n    values: {\n      ...decoded,\n      chartColor,\n    },","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/shadcn-ui/ui/blob/efac5987074af84ece57c367c6dd83387b967022/packages/shadcn/src/commands/preset.ts#L25-L61","documentation":"decodePresetCode calls decodePreset, which bit-unpacks the base62 preset string with a version-prefix character. If the code is malformed — bad version prefix, wrong length, checksum mismatch, non-base62 characters — decodePreset returns null and decodePresetCode throws.","triggerScenarios":"Calling `shadcn preset decode <code>` (or the decodePresetCode API) with a string that is not a valid shadcn preset code for the installed version.","commonSituations":"Truncated code from copy-paste, wrong/unknown version-prefix character (code[0]), code produced by an incompatible shadcn version, manual typo, URL-decoded fragment that lost characters.","solutions":["Regenerate the code at ui.shadcn.com/create and copy it in full.","Ensure the leading version character matches a version your shadcn understands.","Pass the code exactly as produced by `shadcn preset encode`."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"import { isPresetCode, decodePreset } from \"@/preset/preset\"\n\nfunction assertDecodablePreset(code: string) {\n  if (!isPresetCode(code) || decodePreset(code) == null) {\n    throw new Error(`Not a valid preset code: ${code}`)\n  }\n}","typeGuard":"import { decodePreset } from \"@/preset/preset\"\n\nfunction isDecodablePresetCode(code: string): boolean {\n  try {\n    return decodePreset(code) != null\n  } catch {\n    return false\n  }\n}","tryCatchPattern":"try {\n  const result = decodePresetCode(code)\n} catch (e) {\n  if (e instanceof Error && /Invalid preset code/.test(e.message)) {\n    // Prompt the user to regenerate the code from ui.shadcn.com/create.\n  }\n  throw e\n}","preventionTips":["Validate with isPresetCode before calling decodePresetCode.","Copy codes from a trusted source; avoid manual transcription."],"tags":["preset","validation","decode"],"backgroundTag":null,"analyzedSha":"efac5987074af84ece57c367c6dd83387b967022","analyzedAt":"2026-08-12T05:00:50.218Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}