imgtool: update a few errors to use click's
Click has better UI for exceptions, so instead of throwing a backtrace,
allow it to print a nicer error message.
Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/scripts/imgtool/main.py b/scripts/imgtool/main.py
index ba58bfd..5ef7943 100755
--- a/scripts/imgtool/main.py
+++ b/scripts/imgtool/main.py
@@ -22,6 +22,7 @@
import sys
from imgtool import image, imgtool_version
from imgtool.version import decode_version
+from .keys import RSAUsageError, ECDSAUsageError, Ed25519UsageError
def gen_rsa2048(keyfile, passwd):
@@ -116,7 +117,10 @@
key = load_key(key)
if key is None:
print("Invalid passphrase")
- key.emit_private(minimal)
+ try:
+ key.emit_private(minimal)
+ except (RSAUsageError, ECDSAUsageError, Ed25519UsageError) as e:
+ raise click.UsageError(e)
@click.argument('imgfile')
@@ -254,7 +258,8 @@
or (isinstance(key, keys.RSA) and
not isinstance(enckey, keys.RSAPublic))):
# FIXME
- raise Exception("Signing and encryption must use the same type of key")
+ raise click.UsageError("Signing and encryption must use the same "
+ "type of key")
img.create(key, enckey, dependencies)
img.save(outfile, hex_addr)