|
8 | 8 | import json |
9 | 9 | import logging |
10 | 10 | from pathlib import Path |
11 | | -from typing import Dict, List, Optional |
| 11 | +from typing import Any, Dict, List, Optional |
12 | 12 |
|
13 | 13 | from pydantic import TypeAdapter |
14 | 14 |
|
@@ -69,8 +69,11 @@ def _save_servers(self) -> None: |
69 | 69 | self._ensure_dirs() |
70 | 70 | servers_data = {name: config.model_dump() for name, config in self._servers.items()} |
71 | 71 |
|
72 | | - with open(self.config_path, "w", encoding="utf-8") as f: |
73 | | - json.dump(servers_data, f, indent=2) |
| 72 | + try: |
| 73 | + with open(self.config_path, "w", encoding="utf-8") as f: |
| 74 | + json.dump(servers_data, f, indent=2) |
| 75 | + except OSError as e: |
| 76 | + logger.error(f"Error saving servers to {self.config_path}: {e}") |
74 | 77 |
|
75 | 78 | def _load_profile_metadata(self) -> Dict[str, ProfileMetadata]: |
76 | 79 | """Load profile metadata from the metadata configuration file.""" |
@@ -99,8 +102,11 @@ def _save_profile_metadata(self) -> None: |
99 | 102 | self._ensure_dirs() |
100 | 103 | metadata_data = {name: meta.model_dump() for name, meta in self._profile_metadata.items()} |
101 | 104 |
|
102 | | - with open(self.metadata_path, "w", encoding="utf-8") as f: |
103 | | - json.dump(metadata_data, f, indent=2) |
| 105 | + try: |
| 106 | + with open(self.metadata_path, "w", encoding="utf-8") as f: |
| 107 | + json.dump(metadata_data, f, indent=2) |
| 108 | + except OSError as e: |
| 109 | + logger.error(f"Error saving profile metadata to {self.metadata_path}: {e}") |
104 | 110 |
|
105 | 111 | def add_server(self, server_config: ServerConfig, force: bool = False) -> bool: |
106 | 112 | """Add a server to the global configuration. |
@@ -359,7 +365,7 @@ def list_profile_metadata(self) -> Dict[str, ProfileMetadata]: |
359 | 365 | """ |
360 | 366 | return self._profile_metadata.copy() |
361 | 367 |
|
362 | | - def get_complete_profile(self, name: str) -> Optional[Dict[str, any]]: |
| 368 | + def get_complete_profile(self, name: str) -> Optional[Dict[str, Any]]: |
363 | 369 | """Get complete profile information including metadata and servers. |
364 | 370 |
|
365 | 371 | Args: |
|
0 commit comments