Skip to content

Commit 8ea3317

Browse files
committed
add checks
1 parent a28d331 commit 8ea3317

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

  • src/arduino/app_internal/core

src/arduino/app_internal/core/ei.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ class EdgeImpulseRunnerFacade:
4242
"""Facade for Edge Impulse Object Detection and Classification."""
4343

4444
def __init__(self):
45-
"""Initialize the EdgeImpulseRunnerFacade with the API path."""
45+
"""Initialize the EdgeImpulseRunnerFacade with the API path.
46+
47+
Raises:
48+
RuntimeError: If the Edge Impulse runner address cannot be resolved.
49+
"""
4650
self.url = self._get_ei_url()
4751
logger.info(f"[{self.__class__.__name__}] URL: {self.url}")
4852

@@ -243,10 +247,15 @@ def _extract_anomaly_score(self, item: dict):
243247
@classmethod
244248
def _get_ei_url(cls):
245249
infra = load_brick_compose_file(cls)
250+
if not infra or "services" not in infra:
251+
raise RuntimeError("Cannot load Brick Compose file to resolve Edge Impulse runner address.")
252+
host = None
246253
for k, v in infra["services"].items():
247254
host = k
248255
break
249-
host = resolve_address(host)
250-
port = 1337
251-
url = f"http://{host}:{port}"
252-
return url
256+
if not host:
257+
raise RuntimeError("Cannot resolve Edge Impulse runner address from Brick Compose file.")
258+
addr = resolve_address(host)
259+
if not addr:
260+
raise RuntimeError("Host address resolution failed for Edge Impulse runner.")
261+
return f"http://{addr}:1337"

0 commit comments

Comments
 (0)