{"record":{"id":"e7b65012b8419970","repo":"shadcn-ui/ui","slug":"error-as-error-message-n-n-usage","errorCode":null,"errorMessage":"${(error as Error).message}\\n\\n${USAGE}","messagePattern":"\\$\\{\\(error as Error\\)\\.message\\}\\\\n\\\\n\\$\\{USAGE\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/v4/scripts/build-registry.mts","lineNumber":207,"sourceCode":"    indexes?: boolean\n    style?: string\n    registry?: string\n  }\n\n  try {\n    ;({ values } = parseArgs({\n      args: argv,\n      options: {\n        examples: { type: \"boolean\" },\n        indexes: { type: \"boolean\" },\n        style: { type: \"string\" },\n        registry: { type: \"string\" },\n      },\n      allowPositionals: false,\n      strict: true,\n    }))\n  } catch (error) {\n    throw new Error(`${(error as Error).message}\\n\\n${USAGE}`)\n  }\n\n  if (values.style !== undefined) {\n    assertKnownTarget(\"--style\", values.style)\n  }\n  if (values.registry !== undefined) {\n    assertKnownTarget(\"--registry\", values.registry)\n  }\n\n  return {\n    examples: values.examples ?? false,\n    indexes: values.indexes ?? false,\n    style: values.style ?? null,\n    registry: values.registry ?? null,\n  }\n}\n\nfunction isFullBuild(options: BuildOptions) {","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/shadcn-ui/ui/blob/efac5987074af84ece57c367c6dd83387b967022/apps/v4/scripts/build-registry.mts#L189-L225","documentation":"parseBuildOptions calls Node's parseArgs with strict:true and allowPositionals:false over a fixed option schema (--examples/--indexes/--style/--registry). parseArgs throws on unknown flags, flags missing a value, repeated boolean flags, or any positional argument. The catch wraps the native message and appends USAGE so the cause and the correct invocation are visible together.","triggerScenarios":"Passing an unknown flag (--styles plural, --target); --style with no following value; --examples=foo (boolean flag given a value); passing a bare positional path argument (rejected because allowPositionals:false).","commonSituations":"Typo'd flag name; copy-pasting an outdated CLI invocation from docs; passing a file path positionally by habit.","solutions":["Read the wrapped message — parseArgs states the exact problem (e.g. 'unknown option' or 'expected value').","Restrict to the four supported flags and give --style/--registry a value.","Do not pass positional arguments; everything must be a named flag."],"exampleFix":"# before\npnpm registry:build --styles base-nova ./extra\n\n# after\npnpm registry:build --style base-nova","handlingStrategy":"validation","validationCode":"import { parseArgs } from \"util\"\nconst ALLOWED = new Set([\"examples\", \"indexes\", \"style\", \"registry\"])\n// pre-check argv tokens before parseArgs\nfor (const tok of argv) {\n  const name = tok.startsWith(\"--\") ? tok.replace(/^--/, \"\").split(\"=\")[0] : null\n  if (name && !ALLOWED.has(name)) throw new Error(`Unknown flag --${name}`)\n}","typeGuard":"function isAllowedFlag(tok: string): boolean {\n  if (!tok.startsWith(\"--\")) return true\n  const name = tok.replace(/^--/, \"\").split(\"=\")[0]\n  return new Set([\"examples\", \"indexes\", \"style\", \"registry\"]).has(name)\n}","tryCatchPattern":null,"preventionTips":["Restrict invocations to --examples, --indexes, --style <id>, --registry <id>.","Never pass positional arguments — parseArgs is configured with allowPositionals:false.","Give string flags (--style/--registry) an explicit value.","Validate argv in a wrapper script before delegating to the build."],"tags":["cli","args","validation","parseargs"],"backgroundTag":null,"analyzedSha":"efac5987074af84ece57c367c6dd83387b967022","analyzedAt":"2026-08-12T05:00:50.218Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}