Skip to content

Commit 6a4c94a

Browse files
committed
improved error message in PrometheusSignal
1 parent 3753f62 commit 6a4c94a

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ environment.add_microgrid(
3838
"solcast2022_global", column="Berlin", params={"scale": 5000}
3939
)),
4040
],
41-
dispatchables=[vs.SimpleBattery(name="battery", capacity=1500, initial_soc=0.8, min_soc=0.3)],
41+
dispatchables=[
42+
vs.SimpleBattery(name="battery", capacity=1500, initial_soc=0.8, min_soc=0.3)
43+
],
4244
)
4345

4446
environment.add_controller(vs.CsvLogger("results/my_experiment"))
45-
4647
environment.run(until=24 * 3600)
4748
```
4849

vessim/signal.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -562,13 +562,19 @@ def __init__(
562562

563563
def _validate_connection(self) -> None:
564564
"""Validate that we can connect to the Prometheus server."""
565-
response = self.requests.get(
566-
f"{self.prometheus_url}/api/v1/query",
567-
params={"query": "up"},
568-
timeout=self.timeout,
569-
auth=self._auth,
570-
)
571-
response.raise_for_status()
565+
try:
566+
response = self.requests.get(
567+
f"{self.prometheus_url}/api/v1/query",
568+
params={"query": "up"},
569+
timeout=self.timeout,
570+
auth=self._auth,
571+
)
572+
response.raise_for_status()
573+
except requests.exceptions.ConnectionError:
574+
raise ConnectionError(
575+
f"Could not connect to Prometheus at '{self.prometheus_url}'. "
576+
f"Make sure the Prometheus server is running and accessible."
577+
) from None
572578

573579
def _fetch_current_value(self) -> float:
574580
"""Fetch the current value from Prometheus."""

0 commit comments

Comments
 (0)