{"record":{"id":"b08175da70308860","repo":"Hmbown/CodeWhale","slug":"runtime-contract-measurement-failed-with-exit-code-proc","errorCode":null,"errorMessage":"runtime-contract measurement failed with exit code {proc.returncode}","messagePattern":"runtime-contract measurement failed with exit code (.+?)","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":412,"sourceCode":"        temporary_path.unlink(missing_ok=True)\n        raise\n\n\ndef run_measurement() -> dict[str, Any]:\n    env = os.environ.copy()\n    env[\"CARGO_NET_OFFLINE\"] = \"true\"\n    proc = subprocess.run(\n        [sys.executable, str(MEASURE_SCRIPT)],\n        cwd=REPO_ROOT,\n        env=env,\n        capture_output=True,\n        text=True,\n        check=False,\n    )\n    sys.stderr.write(proc.stderr)\n    if proc.returncode != 0:\n        sys.stdout.write(proc.stdout)\n        raise RuntimeContractError(\n            f\"runtime-contract measurement failed with exit code {proc.returncode}\"\n        )\n    try:\n        receipt = json.loads(proc.stdout)\n    except json.JSONDecodeError as error:\n        raise RuntimeContractError(f\"measurement emitted invalid JSON: {error}\") from error\n    if not isinstance(receipt, dict):\n        raise RuntimeContractError(\"measurement top level must be an object\")\n    validate_receipt(receipt)\n    return receipt\n\n\ndef update_command(receipt_path: Path | None, budget_path: Path) -> str:\n    parts = [\"python3\", \"scripts/check-runtime-contract-budget.py\"]\n    if receipt_path is not None:\n        parts.extend([\"--receipt\", str(receipt_path)])\n    if budget_path != BUDGET_PATH:\n        parts.extend([\"--budget\", str(budget_path)])","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-runtime-contract-budget.py#L394-L430","documentation":"run_measurement shells out to scripts/measure-runtime-contract.py (with Cargo forced offline) and requires exit code 0, because the checker can only interpret a successfully produced receipt. If the measurement subprocess exits non-zero, the captured stdout is flushed for debugging and RuntimeContractError is raised with the exit code.","triggerScenarios":"Running the checker without `--receipt` when measure-runtime-contract.py fails: cargo build errors, offline Cargo cannot fetch dependencies, missing toolchain, or the measure script itself raising (e.g. it cannot locate crates/tui sources).","commonSituations":"No network and no vendored cargo deps in a fresh clone; Rust toolchain absent or wrong version; running the script from a context where REPO_ROOT-relative paths or cargo are unavailable; a genuine compile error on the branch.","solutions":["Read the measurement's stderr (reprinted to your terminal) to find the underlying cargo/script failure and fix it.","Run `python3 scripts/measure-runtime-contract.py` directly to see the full error interactively.","Ensure the Rust toolchain is installed and `cargo build` works offline (`cargo build --offline`) or vendor/fetch dependencies where network is allowed.","If you only want to validate an existing artifact, pass `--receipt <file>` to skip compilation entirely."],"exampleFix":"// before: full run failing offline\npython3 scripts/check-runtime-contract-budget.py\n// after: check existing receipt instead, or fix cargo first\npython3 scripts/check-runtime-contract-budget.py --receipt receipt.json","handlingStrategy":"try-catch","validationCode":"import shutil, subprocess\nassert shutil.which(\"cargo\"), \"cargo not on PATH\"\nsubprocess.run([\"cargo\", \"build\", \"--offline\"], check=True, capture_output=True)","typeGuard":"def can_measure() -> bool:\n    import shutil\n    return shutil.which(\"cargo\") is not None and MEASURE_SCRIPT.exists()","tryCatchPattern":"try:\n    receipt = run_measurement()\nexcept RuntimeContractError as e:\n    print(f\"measurement failed: {e}; see stderr above\", file=sys.stderr)\n    sys.exit(e.exit_code)","preventionTips":["Pre-install the Rust toolchain and vendor cargo deps for offline CI.","Run measure-runtime-contract.py standalone first to surface build errors directly.","Use --receipt to validate existing artifacts without compiling."],"tags":["subprocess","build","cargo","contract-check"],"backgroundTag":"command-not-found","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"}