From f03544166867af3c8cbdde0c072ccaf88c8b06d0 Mon Sep 17 00:00:00 2001 From: Rustam Ismayilov Date: Thu, 23 May 2024 11:35:53 +0200 Subject: [PATCH] imgtool: Unify File not found error messages Signed-off-by: Rustam Ismayilov Change-Id: I67e614811c31e786efebc05b9264611d6bb17edb --- scripts/imgtool/dumpinfo.py | 2 +- scripts/imgtool/image.py | 4 ++-- scripts/imgtool/main.py | 2 +- scripts/tests/test_sign.py | 2 +- scripts/tests/test_verify.py | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/imgtool/dumpinfo.py b/scripts/imgtool/dumpinfo.py index 3f97a49f5..20cc63df7 100644 --- a/scripts/imgtool/dumpinfo.py +++ b/scripts/imgtool/dumpinfo.py @@ -140,7 +140,7 @@ def dump_imginfo(imgfile, outfile=None, silent=False): with open(imgfile, "rb") as f: b = f.read() except FileNotFoundError: - raise click.UsageError("Image file not found ({})".format(imgfile)) + raise click.UsageError(f"Image file not found: {imgfile}") # Parsing the image header _header = struct.unpack('IIHHIIBBHI', b[:28]) diff --git a/scripts/imgtool/image.py b/scripts/imgtool/image.py index a30d53bf2..12ea981f7 100644 --- a/scripts/imgtool/image.py +++ b/scripts/imgtool/image.py @@ -238,7 +238,7 @@ def load(self, path): with open(path, 'rb') as f: self.payload = f.read() except FileNotFoundError: - raise click.UsageError("Input file not found") + raise click.UsageError(f"Image file not found: {path}") # Add the image header if needed. if self.pad_header and self.header_size > 0: @@ -647,7 +647,7 @@ def verify(imgfile, key): with open(imgfile, 'rb') as f: b = f.read() except FileNotFoundError: - raise click.UsageError(f"Image file {imgfile} not found") + raise click.UsageError(f"Image file not found: {imgfile}") magic, _, header_size, _, img_size = struct.unpack('IIHHI', b[:16]) version = struct.unpack('BBHI', b[20:28]) diff --git a/scripts/imgtool/main.py b/scripts/imgtool/main.py index e1923a7a2..60f98dbd2 100755 --- a/scripts/imgtool/main.py +++ b/scripts/imgtool/main.py @@ -91,7 +91,7 @@ def load_key(keyfile): try: key = keys.load(keyfile) except FileNotFoundError as e: - print("Key File Not Found in the path: " + keyfile) + print(f"Key file not found: {keyfile}") raise e if key is not None: return key diff --git a/scripts/tests/test_sign.py b/scripts/tests/test_sign.py index 0f10f172b..8b93525b1 100644 --- a/scripts/tests/test_sign.py +++ b/scripts/tests/test_sign.py @@ -1264,7 +1264,7 @@ def test_sign_hex_file_not_exists(self, key_type, tmp_path_persistent): ], ) assert result.exit_code != 0 - assert "Input file not found" in result.output + assert "Image file not found" in result.output @pytest.mark.parametrize("key_type", KEY_TYPES) def test_sign_hex_padded(self, key_type, tmp_path_persistent): diff --git a/scripts/tests/test_verify.py b/scripts/tests/test_verify.py index 70d1d6801..9aacfaa8a 100644 --- a/scripts/tests/test_verify.py +++ b/scripts/tests/test_verify.py @@ -109,7 +109,7 @@ def test_verify_key_not_exists(self, key_type, tmp_path_persistent): ], ) assert result.exit_code != 0 - assert "File Not Found" in result.stdout + assert "Key file not found" in result.stdout @pytest.mark.parametrize("key_type", KEY_TYPES) def test_verify_image_not_exists(self, key_type, tmp_path_persistent): @@ -127,7 +127,7 @@ def test_verify_image_not_exists(self, key_type, tmp_path_persistent): ], ) assert result.exit_code != 0 - assert "File Not Found" in result.stdout + assert "Image file not found" in result.stdout @pytest.mark.parametrize("key_type", ("rsa-3072",)) def test_verify_key_inv_magic(self, key_type, tmp_path_persistent):