From f83676f5f88116bf3fae5d5aa720c170345760b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Fri, 17 Nov 2023 10:42:50 +0100 Subject: [PATCH] Improve error messages --- pynitrokey/nk3/admin_app.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pynitrokey/nk3/admin_app.py b/pynitrokey/nk3/admin_app.py index a6285e3f..9c82df37 100644 --- a/pynitrokey/nk3/admin_app.py +++ b/pynitrokey/nk3/admin_app.py @@ -79,11 +79,15 @@ def from_int(cls, i: int) -> Optional["FactoryResetStatus"]: def check(cls, i: int, msg: str) -> None: status = FactoryResetStatus.from_int(i) if status != FactoryResetStatus.SUCCESS: - if status: - error = str(status) - else: - error = f"unknown error {i:x}" - raise Exception(f"{msg}: {error}") + if status is None: + raise Exception(f"Unknown error {i:x}") + if status == FactoryResetStatus.NOT_CONFIRMED: + error = "Operation was not confirmed with touch" + elif status == FactoryResetStatus.APP_NOT_ALLOWED: + error = "The application does not support factory reset through nitropy" + elif status == APP_FAILED_PARSE: + error = "The application name must be utf-8" + local_critical(f"{msg}: {error}", support_hint=False) @enum.unique