Skip to content

Commit f451651

Browse files
committed
Move error handling to startup commands
1 parent 08a3233 commit f451651

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

justfile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,17 @@ repl:
3939
#!/usr/bin/env bash
4040
uv run --with ptpython ptpython -i <(cat << EOF
4141
from blueapi.client import BlueapiClient
42+
from blueapi.client.rest import ServiceUnavailableError
4243
bc = BlueapiClient.from_config_file("tests/system_tests/config.yaml").with_instrument_session("cm12345-1")
43-
bc.login()
44+
try:
45+
bc.login()
46+
except KeyboardInterrupt:
47+
print("Login cancelled")
48+
except ServiceUnavailableError:
49+
print("Couldn't access blueapi server to log in")
50+
except Exception as e:
51+
import traceback
52+
print("Couldn't log in")
53+
traceback.print_exception(e, chain=False)
4454
EOF
4555
)

src/blueapi/client/client.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -770,11 +770,8 @@ def login(self, token_path: Path | None = None):
770770
auth = SessionManager(
771771
oidc, cache_manager=SessionCacheManager(token_path)
772772
)
773-
try:
774-
auth.start_device_flow()
775-
self._rest.session_manager = auth
776-
except KeyboardInterrupt:
777-
pass
773+
auth.start_device_flow()
774+
self._rest.session_manager = auth
778775
else:
779776
print("Server is not configured to use authentication!")
780777

0 commit comments

Comments
 (0)