{"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":"console","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scripts/check-provider-registry.py","lineNumber":112,"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":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-provider-registry.py#L94-L130","documentation":"extract_match_block() scans Rust source for a signature and then walks braces to extract the body of the following match block. This error means the signature was found (or its position was supplied) but brace matching never returned to depth 0 before end of input, so the match body could not be delimited. Usually the source was reformatted or the match was replaced with another construct.","triggerScenarios":"Called from parse_aliases_for_variant when the text following the target signature in the Rust source has unbalanced braces within the scanned region, the match block was removed or converted to if-lets, or a comment/string confuses the naive brace counter.","commonSituations":"Refactoring ProviderKind's parse impl in provider_kind.rs (moving it, converting match to a different form); partially applied edits leaving syntax unbalanced; the signature string in the guard no longer matching after a rename.","solutions":["Restore the match-based parse impl for the variant in provider_kind.rs (or wherever the guard reads it)","Update the guard's signature string to match the refactored code shape","Check the Rust source compiles (rustfmt/cargo check) — unbalanced braces indicate a broken edit"],"exampleFix":"// before: match s { ... } replaced by if-let chain, guard can't find match block\n// after:  restore `impl ProviderKind { pub fn parse(s: &str) -> Option<Self> { match s { \"alias\" => Some(Variant), ... } } }`","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    body = extract_match_block(source, signature)\nexcept ValueError as e:\n    print(f\"parse impl shape changed: {e}\", file=sys.stderr)\n    sys.exit(1)","preventionTips":["Keep the parse impl match-based and brace-balanced in provider_kind.rs","Run cargo check before running the guard so broken edits are caught early","Update the guard's signature constants together with any refactor"],"tags":["python","rust","parsing","provider-registry"],"backgroundTag":"unexpected-response-shape","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"}