{"record":{"id":"3af665d7a014938a","repo":"Hmbown/CodeWhale","slug":"error-msg","errorCode":null,"errorMessage":"error: {msg}","messagePattern":"error: (.+?)","errorType":"console","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"scripts/catalog_models_dev.py","lineNumber":46,"sourceCode":"\nimport argparse\nimport json\nimport os\nimport sys\nimport urllib.error\nimport urllib.request\nfrom pathlib import Path\nfrom typing import Any\n\nDEFAULT_MODELS_DEV_URL = \"https://models.dev/catalog.json\"\nDEFAULT_OPENROUTER_MODELS_URL = \"https://openrouter.ai/api/v1/models\"\nUSER_AGENT = \"CodeWhale-catalog-automation/0.9.0 (+https://github.com/Hmbown/CodeWhale)\"\nFETCH_TIMEOUT_SECS = 60\n\n\ndef die(msg: str, code: int = 1) -> None:\n    print(f\"error: {msg}\", file=sys.stderr)\n    raise SystemExit(code)\n\n\ndef load_json_bytes(raw: bytes, source: str) -> Any:\n    try:\n        text = raw.decode(\"utf-8\")\n    except UnicodeDecodeError as exc:\n        die(f\"{source}: not utf-8 ({exc})\")\n    try:\n        return json.loads(text)\n    except json.JSONDecodeError as exc:\n        die(f\"{source}: invalid JSON ({exc})\")\n\n\ndef fetch_url(url: str) -> bytes:\n    req = urllib.request.Request(\n        url,\n        headers={\n            \"User-Agent\": USER_AGENT,","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/catalog_models_dev.py#L28-L64","documentation":"die() is the central fatal-error helper of scripts/catalog_models_dev.py: it prints 'error: <msg>' to stderr and exits with a nonzero status. Nearly every failure path in this catalog-refresh tool (bad JSON, failed HTTP fetch, malformed catalog shape, OpenRouter refresh problems) funnels through it, so the underlying cause is whatever message was passed in.","triggerScenarios":"Any call site detects a failure and calls die(msg): load_json_bytes on undecodable/invalid JSON, fetch_url on a failed download, load_models_dev_catalog or ensure_models_dev_shape on structurally wrong catalog data, cmd_refresh/refresh_openrouter on network or API errors.","commonSituations":"models.dev or OpenRouter returning 5xx or rate-limit responses; offline/CI network restrictions; upstream catalog schema drift breaking ensure_models_dev_shape; a truncated or HTML error page saved where JSON was expected.","solutions":["Read the msg on stderr to identify which step failed (decode, fetch, or shape validation)","Re-run the refresh to rule out a transient network/API failure","Inspect the fetched payload at the failing source for HTML error pages or schema changes","If upstream schema drifted, update ensure_models_dev_shape to accept the new layout"],"exampleFix":"# before\nraise SystemExit(1)\n# after\ndie(f\"failed to refresh catalog from {url}: HTTP {status}\")","handlingStrategy":"try-catch","validationCode":"import urllib.request\ntry:\n    urllib.request.urlopen(\"https://models.dev/api.json\", timeout=60)\nexcept Exception as exc:\n    print(\"catalog source unreachable:\", exc)","typeGuard":null,"tryCatchPattern":"try:\n    refresh_catalog()\nexcept SystemExit:\n    # die() already printed 'error: ...' to stderr; inspect msg before retry\n    raise","preventionTips":["Check models.dev/OpenRouter status before scheduled refreshes","Pin and review upstream schema changes; test ensure_models_dev_shape against a saved snapshot","Run refreshes with network retries/backoff so transient failures don't die immediately","Keep the stderr message in monitoring/alerts to identify the failing step fast"],"tags":["cli","network","catalog"],"backgroundTag":"http-request-failed","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"}