Skip to content

Commit e765e0e

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

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
@@ -333,7 +333,7 @@ def load(self, path):
333333
self.infile_data = f.read()
334334
self.payload = copy.copy(self.infile_data)
335335
except FileNotFoundError:
336-
raise click.UsageError("Input file not found")
336+
raise click.UsageError(f"Image file not found: {path}")
337337
self.image_size = len(self.payload)
338338

339339
# Add the image header if needed.
@@ -779,7 +779,7 @@ def verify(imgfile, key):
779779
with open(imgfile, 'rb') as f:
780780
b = f.read()
781781
except FileNotFoundError:
782-
raise click.UsageError(f"Image file {imgfile} not found")
782+
raise click.UsageError(f"Image file not found: {imgfile}")
783783

784784
magic, _, header_size, _, img_size = struct.unpack('IIHHI', b[:16])
785785
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
@@ -103,7 +103,7 @@ def load_key(keyfile):
103103
try:
104104
key = keys.load(keyfile)
105105
except FileNotFoundError as e:
106-
print("Key File Not Found in the path: " + keyfile)
106+
print(f"Key file not found: {keyfile}")
107107
raise e
108108
if key is not None:
109109
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)