{"record":{"id":"468593dab7261053","repo":"ruvnet/RuView","slug":"failed-to-save-domain-configuration-e","errorCode":null,"errorMessage":"Failed to save domain configuration: {e}","messagePattern":"Failed to save domain configuration: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"archive/v1/src/config/domains.py","lineNumber":481,"sourceCode":"        # Load alerts config\n        if \"alerts\" in data:\n            config.alerts = AlertConfig(**data[\"alerts\"])\n    \n    except Exception as e:\n        raise ValueError(f\"Failed to load domain configuration: {e}\")\n    \n    return config\n\n\ndef save_domain_config_to_file(config: DomainConfig, file_path: str):\n    \"\"\"Save domain configuration to file.\"\"\"\n    import json\n    \n    try:\n        with open(file_path, 'w') as f:\n            json.dump(config.to_dict(), f, indent=2)\n    except Exception as e:\n        raise ValueError(f\"Failed to save domain configuration: {e}\")","sourceCodeStart":463,"sourceCodeEnd":481,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/archive/v1/src/config/domains.py#L463-L481","documentation":"Wrapper exception in save_domain_config_to_file in archive/v1/src/config/domains.py. It serializes the config with config.to_dict() and json.dump(...)s it to the given path; any failure — unwritable destination (PermissionError), missing parent directory (FileNotFoundError), or TypeError from non-JSON-serializable values in to_dict() — is re-raised as ValueError('Failed to save domain configuration: {e}').","triggerScenarios":"Saving to a path whose parent directory does not exist; saving into a read-only mount or a directory without write permission; to_dict() containing datetime, numpy, or set values that json.dump cannot serialize (TypeError: Object of type X is not JSON serializable); disk full during write.","commonSituations":"First run writing to data/config/domains.json before creating data/config; containers with read-only config volumes; configs enriched with runtime objects (timestamps, model handles) that were never converted to primitives.","solutions":["Read the chained message after 'Failed to save domain configuration:' to distinguish permission vs serialization errors","Create parent directories first: Path(file_path).parent.mkdir(parents=True, exist_ok=True)","If TypeError, make to_dict() return JSON-safe values or pass default=str to json.dump","Verify write permission on the directory (touch a temp file) before saving"],"exampleFix":"# before\nwith open(file_path, 'w') as f:\n    json.dump(config.to_dict(), f, indent=2)\n\n# after\nfrom pathlib import Path\nPath(file_path).parent.mkdir(parents=True, exist_ok=True)\nwith open(file_path, 'w') as f:\n    json.dump(config.to_dict(), f, indent=2, default=str)","handlingStrategy":"try-catch","validationCode":"import json, os\nfrom pathlib import Path\n\ndest = Path(\"config/domains.json\")\ndest.parent.mkdir(parents=True, exist_ok=True)\nassert os.access(dest.parent, os.W_OK), f\"no write permission in {dest.parent}\"\njson.dumps(config.to_dict(), default=str)  # serialization errors surface here","typeGuard":"def is_json_serializable(obj) -> bool:\n    try:\n        json.dumps(obj, default=str)\n        return True\n    except (TypeError, ValueError):\n        return False","tryCatchPattern":"try:\n    save_domain_config_to_file(config, path)\nexcept ValueError as e:\n    # distinguishes permission vs serialization failures via the chained message\n    raise RuntimeError(f\"config save failed: {e}\") from None","preventionTips":["Create parent directories and confirm write access before saving","Keep to_dict() output JSON-safe (primitives only) or pass default=str","Write to a temp file then atomically rename so a failed save never truncates the config"],"tags":["config","io","json","serialization","filesystem","python"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}