{"record":{"id":"dac6e477976094a7","repo":"Hmbown/CodeWhale","slug":"fragment-cap-not-an-int-pattern","errorCode":null,"errorMessage":"fragment cap not an int: {pattern}","messagePattern":"fragment cap not an int: (.+?)","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":463,"sourceCode":"    Static check — no cargo needed. Fails closed if the fragment module is\n    missing, if any cap has been raised without review, or if the\n    project-instruction import is absent.\n    \"\"\"\n    try:\n        text = FRAGMENT_MODULE.read_text(encoding=\"utf-8\")\n    except FileNotFoundError as error:\n        raise RuntimeContractError(\n            f\"missing bounded fragment module: {FRAGMENT_MODULE} ({error})\"\n        ) from error\n\n    def const_value(pattern: str) -> int:\n        match = re.search(pattern, text)\n        if not match:\n            raise RuntimeContractError(f\"fragment cap missing: {pattern}\")\n        try:\n            return int(match.group(1).replace(\"_\", \"\"))\n        except ValueError as error:\n            raise RuntimeContractError(f\"fragment cap not an int: {pattern}\") from error\n\n    max_tokens = const_value(r\"pub const MAX_FRAGMENT_TOKENS:\\s*usize\\s*=\\s*([0-9_]+)\")\n    if max_tokens != FRAGMENT_MAX_TOKENS_CEILING:\n        raise RuntimeContractError(\n            f\"MAX_FRAGMENT_TOKENS must be {FRAGMENT_MAX_TOKENS_CEILING}, got {max_tokens}\"\n        )\n    # MAX_FRAGMENT_BYTES must be defined as MAX_FRAGMENT_TOKENS * 4 (canonical)\n    # or as a literal 40000. Either way the derived ceiling is 40_000.\n    has_multiplication = re.search(\n        r\"pub const MAX_FRAGMENT_BYTES:\\s*usize\\s*=\\s*MAX_FRAGMENT_TOKENS\\s*\\*\\s*4\", text\n    )\n    bytes_literal = re.search(\n        r\"pub const MAX_FRAGMENT_BYTES:\\s*usize\\s*=\\s*([0-9_]+)\", text\n    )\n    if bytes_literal:\n        literal = int(bytes_literal.group(1).replace(\"_\", \"\"))\n        if literal != FRAGMENT_MAX_BYTES_CEILING:\n            raise RuntimeContractError(","sourceCodeStart":445,"sourceCodeEnd":481,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-runtime-contract-budget.py#L445-L481","documentation":"const_value found a cap declaration but its captured value could not be parsed as an integer after stripping underscores (int() raised ValueError). The checker converts this into RuntimeContractError naming the pattern. Caps must be plain integer literals; expressions, hex, or suffixes are rejected so the derived ceiling math stays exact.","triggerScenarios":"The regex matched a declaration whose value is non-numeric — e.g. `MAX_FRAGMENT_TOKENS: usize = MAX_TOKENS / 2;`, a hex literal like 0x2710, or a value with a stray character captured by an overly broad pattern.","commonSituations":"A developer changed the constant to a computed expression; hex or scientific notation used; capture group grabbed surrounding text due to a regex edit.","solutions":["Change the Rust constant back to a decimal integer literal with optional underscores (e.g. 10_000).","If it must be computed, compute the literal in Rust and keep the checker's regex fed by a plain literal alias.","Verify the regex capture group (group(1)) covers only the digits in check_fragment_caps.","Re-run the checker to confirm all caps parse."],"exampleFix":"// before\npub const MAX_FRAGMENT_BYTES: usize = MAX_FRAGMENT_TOKENS * 4;\n// after (checker reads literals)\npub const MAX_FRAGMENT_TOKENS: usize = 10_000;\npub const MAX_FRAGMENT_BYTES: usize = 40_000;","handlingStrategy":"validation","validationCode":"import re\ntext = open(\"crates/core/src/bounded_fragments.rs\").read()\nm = re.search(r\"pub const MAX_FRAGMENT_TOKENS:\\\\s*usize\\\\s*=\\\\s*([0-9_]+)\", text)\nassert m and m.group(1).replace(\"_\", \"\").isdigit(), \"cap must be a decimal int literal\"","typeGuard":"def is_int_literal(text: str) -> bool:\n    return text.replace(\"_\", \"\").isdigit()","tryCatchPattern":"try:\n    caps = {p: const_value(p) for p in CAP_PATTERNS}\nexcept ValueError as e:\n    print(f\"non-integer cap: {e}\", file=sys.stderr)\n    sys.exit(1)","preventionTips":["Use plain decimal literals with underscores; no hex, no expressions.","If a cap must be derived, also expose a literal the checker can parse.","Verify capture groups only span digits after editing regexes."],"tags":["parsing","contract-check","rust","integer"],"backgroundTag":"invalid-argument-format","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"}