{"record":{"id":"53565a8a8b0a52ac","repo":"Hmbown/CodeWhale","slug":"could-not-parse-match-block-after-signature-r","errorCode":null,"errorMessage":"could not parse match block after {signature!r}","messagePattern":"could not parse match block after (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scripts/check-provider-registry.py","lineNumber":101,"sourceCode":"    return source[start:end]\n\n\ndef extract_match_block(\n    source: str, signature: str, context: str, start: int = 0\n) -> str:\n    start = require_index(source, signature, context, start)\n    match_start = require_index(source, \"match\", f\"match block after {signature!r}\", start)\n    brace_start = require_index(source, \"{\", f\"match block after {signature!r}\", match_start)\n    depth = 0\n    for index in range(brace_start, len(source)):\n        char = source[index]\n        if char == \"{\":\n            depth += 1\n        elif char == \"}\":\n            depth -= 1\n            if depth == 0:\n                return source[brace_start + 1 : index]\n    raise ValueError(f\"could not parse match block after {signature!r}\")\n\n\ndef parse_aliases_for_variant(source: str, enum_name: str, variant: str, context: str) -> set[str]:\n    # `ProviderKind`'s enum + identity impl (incl. `parse`) live in\n    # provider_kind.rs after the config module split; read the impl from there\n    # regardless of the file the caller passed for other lookups.\n    if enum_name == \"ProviderKind\":\n        source = read(PROVIDER_KIND_RS)\n        context = \"crates/config/src/provider_kind.rs\"\n    impl_start = require_index(source, f\"impl {enum_name}\", context)\n    block = extract_match_block(\n        source,\n        \"pub fn parse(value: &str) -> Option<Self>\",\n        context,\n        impl_start,\n    )\n    match_arm = re.search(\n        rf'((?:\"[^\"]+\"\\s*\\|\\s*)*\"[^\"]+\")\\s*=>\\s*Some\\(Self::{variant}\\)',","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/scripts/check-provider-registry.py#L83-L119","documentation":"extract_match_block scans forward from the '{' after the first `match` keyword following a signature, counting brace depth; this error means depth never returned to zero before end-of-file. Practically, the scanned region opened more braces than it closed — most often a '{' or '}' inside a string literal of a parse arm, because the scanner does not understand Rust strings or comments. It is a parse-shape failure of the source the checker reads, not ordinary registry drift.","triggerScenarios":"An alias or id literal inside the enum's `parse` match contains an unbalanced brace; the file is truncated so the match block never closes; code between the signature and the real match introduces braces that desynchronize the naive depth count.","commonSituations":"Unusually-shaped provider alias strings; partial copies of provider files; macro-generated arms that confuse the scanner.","solutions":["Inspect the text between the `pub fn parse...` signature and end-of-file for unbalanced braces, especially inside string literals","Rewrite the offending literal to avoid brace characters","If the parse function's shape changed, update the needles or logic in extract_match_block within scripts/check-provider-registry.py"],"exampleFix":"// before (provider_kind.rs, inside parse)\n\"curly{{id\" => Some(Self::Custom),  // stray brace breaks the naive depth count\n// after\n\"curly-id\" => Some(Self::Custom),","handlingStrategy":"try-catch","validationCode":"block = extract_match_block(source, 'pub fn parse(value: &str) -> Option<Self>', context)\nassert block.count('{') == block.count('}'), 'unbalanced braces in match block'","typeGuard":null,"tryCatchPattern":"try:\n    aliases = parse_aliases_for_variant(source, enum, variant, context)\nexcept ValueError as e:\n    report_parse_failure(str(e)); raise","preventionTips":["Avoid brace characters in alias and id literals","Keep the parse match block free of macro trickery","Update the scanner whenever the parse function's shape changes"],"tags":["python","parsing","rust","static-analysis"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}