Skip to content

Commit 68a2b53

Browse files
committed
fix(python): raise SandboxError instead of FileNotFoundError or KeyError
1 parent f0f17bf commit 68a2b53

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

python/openshell/sandbox.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,12 @@ def from_active_cluster(
153153
/ cluster_name
154154
/ "metadata.json"
155155
)
156-
metadata = json.loads(metadata_path.read_text())
156+
try:
157+
metadata = json.loads(metadata_path.read_text())
158+
except FileNotFoundError:
159+
raise SandboxError(f"gateway '{cluster_name}' not found")
160+
if "gateway_endpoint" not in metadata:
161+
raise SandboxError(f"gateway '{cluster_name}' metadata missing endpoint")
157162
parsed = urlparse(metadata["gateway_endpoint"])
158163
host = parsed.hostname or "127.0.0.1"
159164
port = parsed.port or (443 if parsed.scheme == "https" else 80)
@@ -613,7 +618,10 @@ def _resolve_active_cluster() -> str:
613618
if env_gateway:
614619
return env_gateway
615620
active_file = _xdg_config_home() / "openshell" / "active_gateway"
616-
value = active_file.read_text().strip()
621+
try:
622+
value = active_file.read_text().strip()
623+
except FileNotFoundError:
624+
raise SandboxError("no active gateway configured")
617625
if value == "":
618626
raise SandboxError("no active gateway configured")
619627
return value

0 commit comments

Comments
 (0)