From 36299ea674f2afbce73f1c90eba85e10e14c09a6 Mon Sep 17 00:00:00 2001 From: brenninc Date: Thu, 2 Jul 2026 09:25:03 +0100 Subject: [PATCH 1/2] better error is username missing --- spinnman/spalloc/spalloc_client.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/spinnman/spalloc/spalloc_client.py b/spinnman/spalloc/spalloc_client.py index 6e95d338..bd2dc47c 100644 --- a/spinnman/spalloc/spalloc_client.py +++ b/spinnman/spalloc/spalloc_client.py @@ -26,7 +26,7 @@ import threading from time import sleep from typing import (Any, Callable, Dict, Final, FrozenSet, Iterable, List, - Mapping, Optional, Tuple, cast) + Mapping, Never, Optional, Tuple, cast) from urllib.parse import urlparse, urlunparse, ParseResult from packaging.version import Version @@ -160,9 +160,12 @@ def __init__( if password is None: password = os.getenv("SPALLOC_PASSWORD", None) - self.__session: Optional[Session] = Session( - service_url, username, password, bearer_token) - obj = self.__session.renew() + try: + self.__session: Optional[Session] = Session( + service_url, username, password, bearer_token) + obj = self.__session.renew() + except SpallocException as ex: + self._session_error(service_url, ex, username, password) v = cast(JsonObject, obj["version"]) self.version = Version( f"{v['major-version']}.{v['minor-version']}.{v['revision']}") @@ -174,6 +177,23 @@ def __init__( self.__nmpi_user = nmpi_user logger.info("established session to {} for {}", service_url, username) + def _session_error( + self, service_url: str, exception: SpallocException, + username: Optional[str], password: Optional[str]) -> Never: + message = f"Unable to connect to {service_url}. " + if username is None: + if password is None: + message += ("Username and password missing. " + "Please add to url or set ENV SPALLOC_USER " + "and SPALLOC_PASSWORD.") + else: + message += ("Username missing. " + "Please add to url or set ENV SPALLOC_USER.") + elif password is None: + message += ("Password missing. " + "Please add to url or set ENV SPALLOC_PASSWORD.") + raise SpallocException(message) from exception + def get_job(self, job_id: str) -> SpallocJob: """ Get a job by its job id. From 3cab4016cc077ccf34e9124b8baabeb3b5ea60ce Mon Sep 17 00:00:00 2001 From: christian-B Date: Thu, 2 Jul 2026 10:57:12 +0100 Subject: [PATCH 2/2] typing_extensions import Never --- spinnman/spalloc/spalloc_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spinnman/spalloc/spalloc_client.py b/spinnman/spalloc/spalloc_client.py index bd2dc47c..a1bbe837 100644 --- a/spinnman/spalloc/spalloc_client.py +++ b/spinnman/spalloc/spalloc_client.py @@ -26,12 +26,12 @@ import threading from time import sleep from typing import (Any, Callable, Dict, Final, FrozenSet, Iterable, List, - Mapping, Never, Optional, Tuple, cast) + Mapping, Optional, Tuple, cast) from urllib.parse import urlparse, urlunparse, ParseResult from packaging.version import Version import requests -from typing_extensions import TypeAlias +from typing_extensions import Never, TypeAlias from websocket import WebSocket # type: ignore from spinn_utilities.abstract_base import AbstractBase, abstractmethod