Skip to content

Commit

Permalink
imgtool: Unify File not found error messages
Browse files Browse the repository at this point in the history
Signed-off-by: Rustam Ismayilov <[email protected]>
Change-Id: I67e614811c31e786efebc05b9264611d6bb17edb
  • Loading branch information
rustammendel committed Jun 21, 2024
1 parent 396f116 commit f035441
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion scripts/imgtool/dumpinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions scripts/imgtool/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion scripts/imgtool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests/test_sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions scripts/tests/test_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit f035441

Please sign in to comment.