Skip to content

Commit bbe9d90

Browse files
committed
imgtool: Unify File not found error messages
Signed-off-by: Rustam Ismayilov <[email protected]> Change-Id: I67e614811c31e786efebc05b9264611d6bb17edb
1 parent 83d64a0 commit bbe9d90

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

scripts/imgtool/dumpinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def dump_imginfo(imgfile, outfile=None, silent=False):
140140
with open(imgfile, "rb") as f:
141141
b = f.read()
142142
except FileNotFoundError:
143-
raise click.UsageError("Image file not found ({})".format(imgfile))
143+
raise click.UsageError(f"Image file not found: {imgfile}")
144144

145145
# Parsing the image header
146146
_header = struct.unpack('IIHHIIBBHI', b[:28])

scripts/imgtool/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def load(self, path):
349349
self.infile_data = f.read()
350350
self.payload = copy.copy(self.infile_data)
351351
except FileNotFoundError:
352-
raise click.UsageError("Input file not found")
352+
raise click.UsageError(f"Image file not found: {path}")
353353

354354
# Add the image header if needed.
355355
if self.pad_header and self.header_size > 0:
@@ -840,7 +840,7 @@ def verify(imgfile, key):
840840
with open(imgfile, 'rb') as f:
841841
b = f.read()
842842
except FileNotFoundError:
843-
raise click.UsageError(f"Image file {imgfile} not found")
843+
raise click.UsageError(f"Image file not found: {imgfile}")
844844

845845
magic, _, header_size, _, img_size = struct.unpack('IIHHI', b[:16])
846846
version = struct.unpack('BBHI', b[20:28])

scripts/imgtool/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def load_key(keyfile):
113113
try:
114114
key = keys.load(keyfile)
115115
except FileNotFoundError as e:
116-
print("Key File Not Found in the path: " + keyfile)
116+
print(f"Key file not found: {keyfile}")
117117
raise e
118118
if key is not None:
119119
return key

scripts/tests/test_sign.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ def test_sign_hex_file_not_exists(self, key_type, tmp_path_persistent):
12641264
],
12651265
)
12661266
assert result.exit_code != 0
1267-
assert "Input file not found" in result.output
1267+
assert "Image file not found" in result.output
12681268

12691269
@pytest.mark.parametrize("key_type", KEY_TYPES)
12701270
def test_sign_hex_padded(self, key_type, tmp_path_persistent):

scripts/tests/test_verify.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def test_verify_key_not_exists(self, key_type, tmp_path_persistent):
109109
],
110110
)
111111
assert result.exit_code != 0
112-
assert "File Not Found" in result.stdout
112+
assert "Key file not found" in result.stdout
113113

114114
@pytest.mark.parametrize("key_type", KEY_TYPES)
115115
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):
127127
],
128128
)
129129
assert result.exit_code != 0
130-
assert "File Not Found" in result.stdout
130+
assert "Image file not found" in result.stdout
131131

132132
@pytest.mark.parametrize("key_type", ("rsa-3072",))
133133
def test_verify_key_inv_magic(self, key_type, tmp_path_persistent):

0 commit comments

Comments
 (0)