{"record":{"id":"e07a299e70ac4040","repo":"Hmbown/CodeWhale","slug":"providerkind-all-uses-unknown-variants-sorted-missing","errorCode":null,"errorMessage":"ProviderKind::ALL uses unknown variants: {sorted(missing)}","messagePattern":"ProviderKind::ALL uses unknown variants: (.+?)","errorType":"console","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scripts/check-provider-registry.py","lineNumber":221,"sourceCode":"        raise ValueError(\"provider!() invocations returned no providers\")\n    return ids\n\n\ndef provider_kind_catalog_ids(\n    provider_kind_rs: str, variant_to_id: dict[str, str]\n) -> set[str]:\n    catalog = re.search(\n        r\"pub const ALL:\\s*\\[Self;\\s*\\d+\\]\\s*=\\s*\\[(.*?)\\];\",\n        provider_kind_rs,\n        flags=re.DOTALL,\n    )\n    if catalog is None:\n        raise ValueError(\"crates/config/src/provider_kind.rs: missing ProviderKind::ALL\")\n    variants = set(re.findall(r\"Self::(\\w+)\", catalog.group(1)))\n    catalog_variant_to_id = {**variant_to_id, \"Custom\": \"custom\"}\n    missing = variants - set(catalog_variant_to_id)\n    if missing:\n        raise ValueError(f\"ProviderKind::ALL uses unknown variants: {sorted(missing)}\")\n    return {catalog_variant_to_id[variant] for variant in variants}\n\n\ndef api_provider_ids(tui_config_rs: str) -> dict[str, str]:\n    # ApiProvider ids derive from ProviderKind ids (via delegation to .kind().as_str())\n    # plus the legacy \"deepseek-cn\" variant that exists only in ApiProvider.\n    variant_to_id = provider_kind_ids(\"\")\n    # ApiProvider::SiliconflowCn maps to ProviderKind::SiliconflowCN\n    if \"SiliconflowCN\" in variant_to_id:\n        variant_to_id[\"SiliconflowCn\"] = variant_to_id[\"SiliconflowCN\"]\n    variant_to_id[\"DeepseekCN\"] = \"deepseek-cn\"\n    return variant_to_id\n\n\ndef provider_tables(config_rs: str) -> set[str]:\n    struct_start = require_index(\n        config_rs, \"pub struct ProvidersToml\", \"crates/config/src/lib.rs\"\n    )","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-provider-registry.py#L203-L239","documentation":"After extracting the ProviderKind::ALL catalog, the script verifies every `Self::X` variant listed there has a mapping to a provider id (variant_to_id from the parse impl, plus the \"Custom\" -> \"custom\" meta-provider). Any variant in ALL without a mapping raises this ValueError. It is a consistency check that the enum's identity/parse impl covers every shipped variant.","triggerScenarios":"Adding a new ProviderKind variant to the ALL array without also adding a parse/alias arm for it in provider_kind.rs, so `Self::NewKind` appears in ALL but not in variant_to_id built from the identity impl.","commonSituations":"A contributor adds a new provider enum variant and forgets to extend the parse match or alias table; a variant is intentionally added to ALL but meant to be unreachable, without registering its id.","solutions":["Read the sorted variant names in the message; add a parse/alias arm for each in provider_kind.rs so variant_to_id includes them.","If the variant should map to an existing id (alias), add it to the alias list for that id rather than a new id.","If a variant was added to ALL by mistake, remove it from the ALL array.","If the mapping scheme changed, update provider_kind_catalog_ids in scripts/check-provider-registry.py (e.g. the catalog_variant_to_id merge) accordingly."],"exampleFix":"// before (provider_kind.rs parse)\n\"openai\" => Ok(Self::OpenAI),\n// after\n\"openai\" => Ok(Self::OpenAI),\n\"newprovider\" | \"np\" => Ok(Self::NewProvider),","handlingStrategy":"validation","validationCode":"variants = set(re.findall(r\"Self::(\\w+)\", all_block))\nknown = set(variant_to_id) | {\"Custom\"}\nunknown = variants - known\nassert not unknown, f\"unmapped ProviderKind variants: {sorted(unknown)}\"","typeGuard":"def all_variants_mapped(all_block: str, variant_to_id: dict) -> bool:\n    variants = set(re.findall(r\"Self::(\\w+)\", all_block))\n    return variants <= (set(variant_to_id) | {\"Custom\"})","tryCatchPattern":"try:\n    ids = provider_kind_catalog_ids(src)\nexcept ValueError as e:\n    print(e); sys.exit(1)  # message lists the offending variants","preventionTips":["When adding a ProviderKind variant, update the parse/alias impl and ALL in the same PR.","Add a unit test in crates/config that asserts every ALL variant parses to an id.","Run scripts/check-provider-registry.py in pre-commit/CI."],"tags":["python","rust","enum","consistency-check"],"backgroundTag":"invalid-enum-value","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"}