-
Notifications
You must be signed in to change notification settings - Fork 0
Error Handling
PyCommander turns failed Commander invocations into typed exceptions so your automation scripts and production-test rigs can react in a structured way. The exception types live in pycommander_core.errors.
Exception
└── PyCommanderError # any non-zero Commander return code (base class)
├── PyCommanderInputError # Commander rejected the arguments (return code -1 / 255)
└── PyCommanderRuntimeError # Commander failed at runtime (return code -2 / 254)
| Exception | Raised when | Return code |
|---|---|---|
PyCommanderInputError |
Commander rejected the arguments (bad/invalid input) |
-1 or 255
|
PyCommanderRuntimeError |
Commander failed at runtime — e.g. the adapter could not be reached, or the operation timed out internally |
-2 or 254
|
PyCommanderError |
Any other non-zero return code; also the base class of the two above | other |
The exception message contains Commander's captured output, which usually explains the failure.
from pathlib import Path
from pycommander import Adapter
from pycommander_core.errors import PyCommanderError, PyCommanderRuntimeError
adapter = Adapter(serial_number="440055955", target_device="EFR32MG24")
try:
adapter.target.flashApplication(filenames=[Path("firmware.hex")])
except PyCommanderRuntimeError as e:
print(f"Commander failed at runtime: {e}")
except PyCommanderError as e:
print(f"Other Commander error: {e}")Because PyCommanderInputError and PyCommanderRuntimeError both inherit from PyCommanderError, catching the base class catches everything; order your except clauses from specific to general.
Synchronous commands run with a timeout (default 300 seconds — CommanderBase.default_timeout_s). If a command exceeds it, a standard Python TimeoutError is raised (not a PyCommanderError). Handle it separately if your flows can run long:
try:
adapter.target.flashApplication(filenames=[Path("firmware.hex")])
except TimeoutError:
print("Commander timed out")
except PyCommanderError as e:
print(f"Commander error: {e}")The high-level helpers validate arguments before invoking Commander, so some failures surface as ordinary Python exceptions rather than PyCommanderError:
-
ValueError— e.g. passing more than one ofserial_number/ip_address/serial_port; an invalidVcomHandshake; an empty range/region list where one is required; an out-of-range region index; an invalid TrustZone string; an out-of-range code version. -
FileNotFoundError— e.g. flashing or writing from a file path that does not exist, or pointingexecutable_pathat a missing executable. -
RuntimeError— e.g. attempting to write a public signing/command key when one already exists in OTP; reopening an already-openAemStream.
There are two distinct failure surfaces, and it helps to keep them separate:
- A non-zero Commander exit raises an exception (as above). This is for genuine command failures.
-
Commandercommand methods return the parsed JSONdict, which typically includes asuccessboolean. The higher-level Adapter-Class and Target-Class helpers read this flag and translate it into return values: a query that "failed gracefully" generally returnsNone, and an action returnsTrue/False. So aTarget.info()returningNonemeans Commander ran but reported no usable result — not that an exception occurred.
A robust pattern combines both:
info = adapter.target.info()
if info is None:
print("Could not read device info")
else:
print(info.part_number)- Logging — record every invocation (including failures) with timestamps.
-
Architecture-and-Packages — how the subprocess
Runnermaps return codes to these exceptions.
PyCommander · GitHub · Simplicity Commander docs · Licensed under the Silicon Labs MSLA
Getting started
Using PyCommander
Topics
Command reference
- Overview
- adapter · aem · vcom · ctune
- device · flash · verify · readmem · extflash
- security
- tokens · nvm3 · littlefs
- convert · ebl · gbl3 · gbl4 · ota · rps · postbuild
- util · serial · mfg917
Contributing