Skip to content

Commit 0851833

Browse files
authored
Fix null check for device status responses in CLI streaming (#169)
* Fix null check for device status responses in CLI streaming The *_with_status() methods return None on gRPC errors, but configure_device(), start_device(), and stop_device() were accessing .code without checking for None first. This caused "'NoneType' object has no attribute 'code'" errors when device operations failed. * bump version 2.4.1
1 parent 3aa87e9 commit 0851833

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name="science-synapse",
9-
version="2.4.0",
9+
version="2.4.1",
1010
description="Client library and CLI for the Synapse API",
1111
author="Science Team",
1212
author_email="team@science.xyz",

synapse/cli/streaming.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,9 @@ def configure_device(device, config, console):
593593

594594
# Apply the configuration to the device
595595
configure_status = device.configure_with_status(config)
596+
if configure_status is None:
597+
console.print("[bold red]Failed to configure device: connection error[/bold red]")
598+
return False
596599
if configure_status.code != StatusCode.kOk:
597600
console.print(
598601
f"[bold red]Failed to configure device: {configure_status.message}[/bold red]"
@@ -610,6 +613,9 @@ def start_device(device, console):
610613

611614
with console.status("Starting device...", spinner="bouncingBall"):
612615
start_status = device.start_with_status()
616+
if start_status is None:
617+
console.print("[bold red]Failed to start device: connection error[/bold red]")
618+
return False
613619
if start_status.code != StatusCode.kOk:
614620
console.print(
615621
f"[bold red]Failed to start device: {start_status.message}[/bold red]"
@@ -621,6 +627,9 @@ def start_device(device, console):
621627
def stop_device(device, console):
622628
with console.status("Stopping device...", spinner="bouncingBall"):
623629
stop_status = device.stop_with_status()
630+
if stop_status is None:
631+
console.print("[bold red]Failed to stop device: connection error[/bold red]")
632+
return False
624633
if stop_status.code != StatusCode.kOk:
625634
console.print(
626635
f"[bold red]Failed to stop device: {stop_status.message}[/bold red]"

0 commit comments

Comments
 (0)