{"record":{"id":"24534c35f2e4fcd6","repo":"Hmbown/CodeWhale","slug":"invalid-label-path-error","errorCode":null,"errorMessage":"invalid {label} {path}: {error}","messagePattern":"invalid (.+?) (.+?): (.+?)","errorType":"validation","errorClass":"PersistenceBacklogError","httpStatus":null,"severity":"error","filePath":"scripts/check-persistence-backlog-budget.py","lineNumber":90,"sourceCode":"    \"enqueue_elapsed_ns\",\n    \"rss_during_delta_bytes\",\n    \"rss_after_delta_bytes\",\n)\nRSS_SAMPLE_FIELDS = (\"rss_before_bytes\", \"rss_during_bytes\", \"rss_after_bytes\")\nRSS_DELTA_FIELDS = (\"rss_during_delta_bytes\", \"rss_after_delta_bytes\")\nSUPPORTED_PLATFORMS = {\"linux\", \"macos\", \"windows\"}\nSOURCE_SHA_PATTERN = re.compile(r\"[0-9a-f]{40}\")\n\n\nclass PersistenceBacklogError(ValueError):\n    \"\"\"A receipt or budget broke the measurement contract.\"\"\"\n\n\ndef load_json(path: Path, label: str) -> dict[str, Any]:\n    try:\n        value = json.loads(path.read_text(encoding=\"utf-8\"))\n    except (OSError, json.JSONDecodeError) as error:\n        raise PersistenceBacklogError(f\"invalid {label} {path}: {error}\") from error\n    if not isinstance(value, dict):\n        raise PersistenceBacklogError(f\"{label} must be a JSON object\")\n    return value\n\n\ndef non_negative_integer(value: Any, field: str) -> int:\n    if isinstance(value, bool) or not isinstance(value, int) or value < 0:\n        raise PersistenceBacklogError(f\"{field} must be a non-negative integer\")\n    return value\n\n\ndef validate_frozen_field(field: str, value: Any, expected: Any) -> None:\n    if type(value) is not type(expected) or value != expected:\n        raise PersistenceBacklogError(\n            f\"receipt {field} must remain {expected!r}, got {value!r}\"\n        )\n\n","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-persistence-backlog-budget.py#L72-L108","documentation":"load_json in scripts/check-persistence-backlog-budget.py reads a JSON file and wraps any OSError (missing/unreadable file) or JSONDecodeError (malformed content) into a PersistenceBacklogError with a message identifying the labeled file and the underlying cause. The budget checker treats unreadable or unparseable inputs as fatal so it never silently validates against stale or missing data.","triggerScenarios":"Calling main with a receipt or budget file path that doesn't exist, has restrictive permissions, or contains invalid JSON (truncated write, trailing comma, HTML error page saved as .json).","commonSituations":"Running the checker before the receipt file was generated; a partially-written artifact from a crashed pipeline; editing the JSON by hand and introducing a syntax error; wrong relative path when invoking from a different working directory.","solutions":["Check the file exists at the given path (ls <path>) and fix the path/working directory","Validate the JSON with python -m json.tool <path> and repair the syntax error","Regenerate the receipt/budget file from the producing pipeline","Check file permissions if OSError mentions access"],"exampleFix":"# before\nbudget = load_json(Path(\"budet.json\"), \"budget\")\n# after\nbudget = load_json(Path(\"budget.json\"), \"budget\")","handlingStrategy":"try-catch","validationCode":"from pathlib import Path\np = Path(\"budget.json\")\nassert p.exists(), f\"{p} missing; generate it first\"\nimport json; json.loads(p.read_text())  # raises early with a clear error","typeGuard":null,"tryCatchPattern":"try:\n    budget = load_json(Path(\"budget.json\"), \"budget\")\nexcept PersistenceBacklogError as exc:\n    print(f\"cannot run budget check: {exc}\")\n    sys.exit(1)","preventionTips":["Generate the receipt/budget files before invoking the checker","Validate JSON with python -m json.tool after any manual edit","Use absolute or repo-root-relative paths so cwd doesn't break resolution","Make the producing pipeline write atomically (temp file + rename) to avoid truncated JSON"],"tags":["json","file-io","validation"],"backgroundTag":"json-parse-error","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"}