{"record":{"id":"139e0acabf2f6feb","repo":"Hmbown/CodeWhale","slug":"name-aliases-unknown-token-target","errorCode":null,"errorMessage":"{name} aliases unknown token {target}","messagePattern":"(.+?) aliases unknown token (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/export-design-tokens.py","lineNumber":45,"sourceCode":"\nCONST_RE = re.compile(\n    r\"^pub const ((?:WHALE|LIGHT)_[A-Z0-9_]+)_RGB: \\(u8, u8, u8\\) = \"\n    r\"(?:\\((\\d+), (\\d+), (\\d+)\\)|((?:WHALE|LIGHT)_[A-Z0-9_]+)_RGB);\",\n    re.MULTILINE,\n)\n\n\n\ndef parse_tokens(text: str) -> list[tuple[str, tuple[int, int, int] | str]]:\n    \"\"\"Return [(NAME, (r, g, b) | alias-NAME)] in source order.\"\"\"\n    tokens: list[tuple[str, tuple[int, int, int] | str]] = []\n    known: set[str] = set()\n    for m in CONST_RE.finditer(text):\n        name = m.group(1)\n        if m.group(5) is not None:\n            target = m.group(5)\n            if target not in known:\n                raise SystemExit(f\"{name} aliases unknown token {target}\")\n            tokens.append((name, target))\n        else:\n            tokens.append((name, (int(m.group(2)), int(m.group(3)), int(m.group(4)))))\n        known.add(name)\n    if not tokens:\n        raise SystemExit(f\"no WHALE_*_RGB consts found in {TOKENS_RS}\")\n    return tokens\n\n\ndef css_name(name: str) -> str:\n    \"\"\"`WHALE_*` exports as `--whale-*`; the Blue Stage light preset's\n    `LIGHT_*` consts export as `--light-*` so the website's paper surface can\n    reference the same light-mode ink and border values the TUI ships.\"\"\"\n    if name.startswith(\"LIGHT_\"):\n        return \"--light-\" + name.removeprefix(\"LIGHT_\").lower().replace(\"_\", \"-\")\n    return \"--whale-\" + name.removeprefix(\"WHALE_\").lower().replace(\"_\", \"-\")\n\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/export-design-tokens.py#L27-L63","documentation":"export-design-tokens.py parses WHALE_*_RGB constants from tokens.rs and resolves aliases. When a constant aliases (group 5) a token name that has not been defined yet, parse_tokens aborts with SystemExit naming the unknown target.","triggerScenarios":"A const like pub const WHALE_X_RGB: Rgb = WHALE_UNDEFINED_RGB; where WHALE_UNDEFINED_RGB was never matched by CONST_RE earlier in the file, or is defined after its use.","commonSituations":"Renaming or deleting a token in tokens.rs while aliases still reference it; typos in the alias name; forward-referencing a const defined later in the file (parser is order-sensitive).","solutions":["Fix the alias target spelling to match an existing WHALE_* token","Define the target token before the aliasing const in tokens.rs","Remove the stale alias if the target token was deleted"],"exampleFix":"// before\npub const WHALE_B_RGB: Rgb = WHALE_Aliased_RGB; // unknown\n// after\npub const WHALE_B_RGB: Rgb = WHALE_A_RGB; // defined earlier","handlingStrategy":"validation","validationCode":"import re\ndefined = set(re.findall(r\"pub const (WHALE_\\w+_RGB)\", tokens_src))\naliased = set(re.findall(r\"WHALE_\\w+_RGB:\\s*Rgb\\s*=\\s*(WHALE_\\w+_RGB);\", tokens_src))\nassert aliased <= defined, f\"unknown alias targets: {aliased - defined}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Define aliased tokens before the alias in the file","Grep for alias targets after renaming/deleting tokens","Add a CI token-export run to catch stale aliases"],"tags":["python","codegen","design-tokens"],"backgroundTag":"resource-not-found","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}