Skip to content

Commit 3b5e17f

Browse files
author
Nils Bars
committed
Replace assertions with graceful error handling in InstanceManager
- Change assert statements to return False in is_running() when SSH proxy or web containers cannot be found - Add RuntimeError with descriptive message in start() when required containers are missing instead of failing silently
1 parent 4cf8d2d commit 3b5e17f

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

webapp/ref/core/instance.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,17 @@ def start(self):
494494
print(f"[INSTANCE] SSH proxy container: {ssh_proxy_container}", flush=True)
495495
print(f"[INSTANCE] Web container: {web_container}", flush=True)
496496

497+
if not ssh_proxy_container:
498+
raise RuntimeError(
499+
f"SSH proxy container '{ssh_proxy_name}' not found. "
500+
"The container may still be starting or has been removed."
501+
)
502+
if not web_container:
503+
raise RuntimeError(
504+
f"Web container '{web_name}' not found. "
505+
"The container may still be starting or has been removed."
506+
)
507+
497508
# Create a network that connects the entry service with the SSH reverse proxy.
498509
entry_to_ssh_network_name = f"{current_app.config['DOCKER_RESSOURCE_PREFIX']}{self.instance.exercise.short_name}-v{self.instance.exercise.version}-ssh-to-entry-{self.instance.id}"
499510

@@ -770,10 +781,12 @@ def is_running(self):
770781
ssh_proxy_container = self.dc.container(
771782
current_app.config["SSH_REVERSE_PROXY_CONTAINER_NAME"]
772783
)
773-
assert ssh_proxy_container
784+
if not ssh_proxy_container:
785+
return False
774786

775787
web_container = self.dc.container(current_app.config["WEB_CONTAINER_NAME"])
776-
assert web_container
788+
if not web_container:
789+
return False
777790

778791
# Check if the SSH reverse proxy and web containers are connected to our network.
779792
# This might not be the case if they were removed and restarted with

0 commit comments

Comments
 (0)