Skip to content

Commit 64c3a66

Browse files
committed
firmware: rework some error strings
Signed-off-by: Tatiana Leon <Tatiana.Leon@digi.com>
1 parent f951044 commit 64c3a66

File tree

1 file changed

+46
-40
lines changed

1 file changed

+46
-40
lines changed

digi/xbee/firmware.py

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,8 @@
139139
_ERROR_DETERMINE_BOOTLOADER_TYPE = "Could not determine the bootloader type: %s"
140140
_ERROR_DEVICE_PROGRAMMING_MODE = "Could not put XBee device into programming mode"
141141
_ERROR_END_DEVICE_ORPHAN = "Could not find the parent node of the end device"
142-
_ERROR_FILE_OTA_FS_NOT_FOUND = "OTA filesystem image file does not exist"
143-
_ERROR_FILE_OTA_FS_NOT_SPECIFIED = "OTA filesystem image file must be specified"
144-
_ERROR_FILE_XBEE_FW_NOT_FOUND = "Could not find XBee binary firmware file '%s'"
145-
_ERROR_FILE_XML_FW_NOT_FOUND = "XML firmware file does not exist"
146-
_ERROR_FILE_XML_FW_NOT_SPECIFIED = "XML firmware file must be specified"
147-
_ERROR_FILE_BOOTLOADER_FW_NOT_FOUND = "Could not find bootloader binary " \
148-
"firmware file '%s'"
142+
_ERROR_FILE_NOT_FOUND = "%s file '%s' not found"
143+
_ERROR_FILE_NOT_SPECIFIED = "%s file must be specified"
149144
_ERROR_FINISH_PROCESS = "Could not finish firmware update process"
150145
_ERROR_FW_START = "Could not start the new firmware"
151146
_ERROR_FW_UPDATE_BOOTLOADER = "Bootloader update error: %s"
@@ -2971,7 +2966,7 @@ def _check_fw_binary_file(self):
29712966
path.stem + self._get_fw_binary_file_extension()))
29722967

29732968
if not _file_exists(self._fw_file):
2974-
self._exit_with_error(_ERROR_FILE_XBEE_FW_NOT_FOUND % self._fw_file,
2969+
self._exit_with_error(_ERROR_FILE_NOT_FOUND % ("XBee firmware", self._fw_file),
29752970
restore_updater=False)
29762971

29772972
def _enter_bootloader_mode_with_break(self):
@@ -3768,8 +3763,8 @@ def _check_bootloader_binary_file(self):
37683763
+ EXTENSION_GBL))
37693764

37703765
if not _file_exists(self._bootloader_fw_file):
3771-
self._exit_with_error(_ERROR_FILE_BOOTLOADER_FW_NOT_FOUND %
3772-
self._bootloader_fw_file, restore_updater=False)
3766+
self._exit_with_error(_ERROR_FILE_NOT_FOUND % ("booloader firmware", self._bootloader_fw_file),
3767+
restore_updater=False)
37733768

37743769
def _transfer_firmware(self):
37753770
"""
@@ -4450,7 +4445,7 @@ def _check_fw_binary_file(self):
44504445
self._ota_fw_file = str(Path(path.parent).joinpath(path.stem + EXTENSION_OTA))
44514446

44524447
if not _file_exists(self._ota_fw_file):
4453-
self._exit_with_error(_ERROR_FILE_XBEE_FW_NOT_FOUND % self._ota_fw_file,
4448+
self._exit_with_error(_ERROR_FILE_NOT_FOUND % ("XBee firmware", self._ota_fw_file),
44544449
restore_updater=False)
44554450

44564451
self._ota_file = _OTAFile(self._ota_fw_file)
@@ -4471,7 +4466,7 @@ def _check_bootloader_binary_file(self):
44714466
self._otb_fw_file = str(Path(path.parent).joinpath(path.stem + EXTENSION_OTB))
44724467

44734468
if not _file_exists(self._otb_fw_file):
4474-
self._exit_with_error(_ERROR_FILE_XBEE_FW_NOT_FOUND % self._otb_fw_file,
4469+
self._exit_with_error(_ERROR_FILE_NOT_FOUND % ("XBee firmware", self._otb_fw_file),
44754470
restore_updater=False)
44764471

44774472
# If asked to check the bootloader file, replace the OTA file with the
@@ -5724,7 +5719,8 @@ def _check_fw_binary_file(self):
57245719
"""
57255720
# Verify the filesystem OTA image file.
57265721
if not _file_exists(self._fs_ota_file):
5727-
self._exit_with_error(_ERROR_FILE_OTA_FS_NOT_FOUND, restore_updater=False)
5722+
self._exit_with_error(_ERROR_FILE_NOT_FOUND % ("OTA filesystem image", self._fs_ota_file),
5723+
restore_updater=False)
57285724

57295725
self._ota_file = _OTAFile(self._fs_ota_file)
57305726
try:
@@ -5850,8 +5846,8 @@ def _check_fw_binary_file(self):
58505846
)
58515847

58525848
if not _file_exists(self._fw_file):
5853-
self._exit_with_error(_ERROR_FILE_XBEE_FW_NOT_FOUND
5854-
% self._fw_file, restore_updater=False)
5849+
self._exit_with_error(_ERROR_FILE_NOT_FOUND % ("XBee firmware", self._fw_file),
5850+
restore_updater=False)
58555851

58565852
def _check_bootloader_binary_file(self):
58575853
"""
@@ -6248,7 +6244,7 @@ def _check_fw_binary_file(self):
62486244
self._fw_file = str(Path(path.parent).joinpath(path.stem + EXTENSION_EBL))
62496245

62506246
if not _file_exists(self._fw_file):
6251-
self._exit_with_error(_ERROR_FILE_XBEE_FW_NOT_FOUND % self._fw_file,
6247+
self._exit_with_error(_ERROR_FILE_NOT_FOUND % ("XBee firmware", self._fw_file),
62526248
restore_updater=False)
62536249

62546250
def _check_bootloader_binary_file(self):
@@ -7020,13 +7016,13 @@ def __init__(self, xbee, xml_fw_path, fw_path=None, bl_fw_path=None,
70207016
if not isinstance(xbee, (XBeeDevice, RemoteXBeeDevice)):
70217017
raise ValueError("Invalid XBee")
70227018
if xml_fw_path is None:
7023-
raise ValueError(_ERROR_FILE_XML_FW_NOT_SPECIFIED)
7019+
raise ValueError(_ERROR_FILE_NOT_SPECIFIED % "XML firmware")
70247020
if not _file_exists(xml_fw_path):
7025-
raise ValueError(_ERROR_FILE_XML_FW_NOT_FOUND)
7021+
raise ValueError(_ERROR_FILE_NOT_FOUND % ("XML firmware", xml_fw_path))
70267022
if fw_path is not None and not _file_exists(fw_path):
7027-
raise ValueError(_ERROR_FILE_XBEE_FW_NOT_FOUND % fw_path)
7023+
raise ValueError(_ERROR_FILE_NOT_FOUND % ("XBee firmware", fw_path))
70287024
if bl_fw_path is not None and not _file_exists(bl_fw_path):
7029-
raise ValueError(_ERROR_FILE_BOOTLOADER_FW_NOT_FOUND % bl_fw_path)
7025+
raise ValueError(_ERROR_FILE_NOT_FOUND % ("booloader firmware", bl_fw_path))
70307026

70317027
self.__xbee = xbee
70327028
self.__xml_path = xml_fw_path
@@ -7126,17 +7122,21 @@ def update_local_firmware(target, xml_fw_file, xbee_firmware_file=None,
71267122
_log.error("ERROR: %s", _ERROR_TARGET_INVALID)
71277123
raise FirmwareUpdateException(_ERROR_TARGET_INVALID)
71287124
if xml_fw_file is None:
7129-
_log.error("ERROR: %s", _ERROR_FILE_XML_FW_NOT_SPECIFIED)
7130-
raise FirmwareUpdateException(_ERROR_FILE_XML_FW_NOT_SPECIFIED)
7125+
error = _ERROR_FILE_NOT_SPECIFIED % "XML firmware"
7126+
_log.error("ERROR: %s", error)
7127+
raise FirmwareUpdateException(error)
71317128
if not _file_exists(xml_fw_file):
7132-
_log.error("ERROR: %s", _ERROR_FILE_XML_FW_NOT_FOUND)
7133-
raise FirmwareUpdateException(_ERROR_FILE_XML_FW_NOT_FOUND)
7129+
error = _ERROR_FILE_NOT_FOUND % ("XML firmware", xml_fw_file)
7130+
_log.error("ERROR: %s", error)
7131+
raise FirmwareUpdateException(error)
71347132
if xbee_firmware_file is not None and not _file_exists(xbee_firmware_file):
7135-
_log.error("ERROR: %s", _ERROR_FILE_XBEE_FW_NOT_FOUND % xbee_firmware_file)
7136-
raise FirmwareUpdateException(_ERROR_FILE_XBEE_FW_NOT_FOUND % xbee_firmware_file)
7133+
error = _ERROR_FILE_NOT_FOUND % ("XBee firmware", xbee_firmware_file)
7134+
_log.error("ERROR: %s", error)
7135+
raise FirmwareUpdateException(error)
71377136
if bootloader_firmware_file is not None and not _file_exists(bootloader_firmware_file):
7138-
_log.error("ERROR: %s", _ERROR_FILE_BOOTLOADER_FW_NOT_FOUND % bootloader_firmware_file)
7139-
raise FirmwareUpdateException(_ERROR_FILE_BOOTLOADER_FW_NOT_FOUND % bootloader_firmware_file)
7137+
error = _ERROR_FILE_NOT_FOUND % ("bootloader firmware", bootloader_firmware_file)
7138+
_log.error("ERROR: %s", error)
7139+
raise FirmwareUpdateException(error)
71407140

71417141
if isinstance(target, XBeeDevice):
71427142
hw_version = target.get_hardware_version()
@@ -7221,17 +7221,21 @@ def update_remote_firmware(remote, xml_fw_file, firmware_file=None, bootloader_f
72217221
_log.error("ERROR: %s", _ERROR_REMOTE_DEVICE_INVALID)
72227222
raise FirmwareUpdateException(_ERROR_TARGET_INVALID)
72237223
if xml_fw_file is None:
7224-
_log.error("ERROR: %s", _ERROR_FILE_XML_FW_NOT_SPECIFIED)
7225-
raise FirmwareUpdateException(_ERROR_FILE_XML_FW_NOT_SPECIFIED)
7224+
error = _ERROR_FILE_NOT_SPECIFIED % "XML firmware"
7225+
_log.error("ERROR: %s", error)
7226+
raise FirmwareUpdateException(error)
72267227
if not _file_exists(xml_fw_file):
7227-
_log.error("ERROR: %s", _ERROR_FILE_XML_FW_NOT_FOUND)
7228-
raise FirmwareUpdateException(_ERROR_FILE_XML_FW_NOT_FOUND)
7228+
error = _ERROR_FILE_NOT_FOUND % ("XML firmware", xml_fw_file)
7229+
_log.error("ERROR: %s", error)
7230+
raise FirmwareUpdateException(error)
72297231
if firmware_file is not None and not _file_exists(firmware_file):
7230-
_log.error("ERROR: %s", _ERROR_FILE_XBEE_FW_NOT_FOUND % firmware_file)
7231-
raise FirmwareUpdateException(_ERROR_FILE_XBEE_FW_NOT_FOUND % firmware_file)
7232+
error = _ERROR_FILE_NOT_FOUND % ("XBee firmware", firmware_file)
7233+
_log.error("ERROR: %s", error)
7234+
raise FirmwareUpdateException(error)
72327235
if bootloader_file is not None and not _file_exists(bootloader_file):
7233-
_log.error("ERROR: %s", _ERROR_FILE_XBEE_FW_NOT_FOUND % bootloader_file)
7234-
raise FirmwareUpdateException(_ERROR_FILE_XBEE_FW_NOT_FOUND % bootloader_file)
7236+
error = _ERROR_FILE_NOT_FOUND % ("XBee firmware", bootloader_file)
7237+
_log.error("ERROR: %s", error)
7238+
raise FirmwareUpdateException(error)
72357239
if not isinstance(max_block_size, int):
72367240
raise ValueError("Maximum block size must be an integer")
72377241
if max_block_size < 0 or max_block_size > 255:
@@ -7331,11 +7335,13 @@ def update_remote_filesystem(remote, ota_fs_file, max_block_size=0, timeout=None
73317335
_log.error("ERROR: %s", _ERROR_REMOTE_DEVICE_INVALID)
73327336
raise FirmwareUpdateException(_ERROR_REMOTE_DEVICE_INVALID)
73337337
if ota_fs_file is None:
7334-
_log.error("ERROR: %s", _ERROR_FILE_OTA_FS_NOT_SPECIFIED)
7335-
raise FirmwareUpdateException(_ERROR_FILE_OTA_FS_NOT_SPECIFIED)
7338+
error = _ERROR_FILE_NOT_SPECIFIED % "OTA filesystem image"
7339+
_log.error("ERROR: %s", error)
7340+
raise FirmwareUpdateException(error)
73367341
if not _file_exists(ota_fs_file):
7337-
_log.error("ERROR: %s", _ERROR_FILE_OTA_FS_NOT_FOUND)
7338-
raise FirmwareUpdateException(_ERROR_FILE_OTA_FS_NOT_FOUND)
7342+
error = _ERROR_FILE_NOT_FOUND % ("OTA filesystem image", ota_fs_file)
7343+
_log.error("ERROR: %s", error)
7344+
raise FirmwareUpdateException(error)
73397345
if not isinstance(max_block_size, int):
73407346
raise ValueError("Maximum block size must be an integer")
73417347
if max_block_size < 0 or max_block_size > 255:

0 commit comments

Comments
 (0)