Hmbown/CodeWhale · error · ValueError

could not parse match block after

Error message

could not parse match block after {signature!r}

What it means

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.

Solutions

  1. Restore the match-based parse impl for the variant in provider_kind.rs (or wherever the guard reads it)
  2. Update the guard's signature string to match the refactored code shape
  3. Check the Rust source compiles (rustfmt/cargo check) — unbalanced braces indicate a broken edit

Example fix

// before: match s { ... } replaced by if-let chain, guard can't find match block
// after:  restore `impl ProviderKind { pub fn parse(s: &str) -> Option<Self> { match s { "alias" => Some(Variant), ... } } }`
Defensive patterns

Strategy: try-catch

Try / catch

try:
    body = extract_match_block(source, signature)
except ValueError as e:
    print(f"parse impl shape changed: {e}", file=sys.stderr)
    sys.exit(1)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/53565a8a8b0a52ac. Report an issue: GitHub.

Appendix: source

Thrown at scripts/check-provider-registry.py:112

    return source[start:end]


def extract_match_block(
    source: str, signature: str, context: str, start: int = 0
) -> str:
    start = require_index(source, signature, context, start)
    match_start = require_index(source, "match", f"match block after {signature!r}", start)
    brace_start = require_index(source, "{", f"match block after {signature!r}", match_start)
    depth = 0
    for index in range(brace_start, len(source)):
        char = source[index]
        if char == "{":
            depth += 1
        elif char == "}":
            depth -= 1
            if depth == 0:
                return source[brace_start + 1 : index]
    raise ValueError(f"could not parse match block after {signature!r}")


def parse_aliases_for_variant(source: str, enum_name: str, variant: str, context: str) -> set[str]:
    # `ProviderKind`'s enum + identity impl (incl. `parse`) live in
    # provider_kind.rs after the config module split; read the impl from there
    # regardless of the file the caller passed for other lookups.
    if enum_name == "ProviderKind":
        source = read(PROVIDER_KIND_RS)
        context = "crates/config/src/provider_kind.rs"
    impl_start = require_index(source, f"impl {enum_name}", context)
    block = extract_match_block(
        source,
        "pub fn parse(value: &str) -> Option<Self>",
        context,
        impl_start,
    )
    match_arm = re.search(
        rf'((?:"[^"]+"\s*\|\s*)*"[^"]+")\s*=>\s*Some\(Self::{variant}\)',

View on GitHub (pinned to 433685b202)