Skip to content

Commit

Permalink
Merge branch '207-uncaught-exception'
Browse files Browse the repository at this point in the history
Handle exception for the devices' listing

Fixes #207
  • Loading branch information
szszszsz committed Mar 15, 2022
2 parents d551528 + e9d3d82 commit b11a6ac
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
5 changes: 3 additions & 2 deletions pynitrokey/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def _list():
fido2.commands["list"].callback()
start.commands["list"].callback()
nk3.commands["list"].callback()
# TODO add other handled models


@click.command()
Expand All @@ -110,5 +111,5 @@ def main() -> None:
except CliException as e:
e.show()
except Exception as e:
logger.warning("An unhandled exception occured", exc_info=True)
local_critical("An unhandled exception occured", e)
logger.warning("An unhandled exception occurred", exc_info=True)
local_critical("An unhandled exception occurred", e)
1 change: 1 addition & 0 deletions pynitrokey/confconsts.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ class Verbosity(IntEnum):
LOG_FORMAT = "%(relativeCreated)-8d %(levelname)6s %(name)10s %(message)s"

GH_ISSUES_URL = "https://github.com/Nitrokey/pynitrokey/issues/"
SUPPORT_URL = "https://support.nitrokey.com/"
SUPPORT_EMAIL = "[email protected]"
18 changes: 13 additions & 5 deletions pynitrokey/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
GH_ISSUES_URL,
LOG_FN,
SUPPORT_EMAIL,
SUPPORT_URL,
VERBOSE,
Verbosity,
)
Expand Down Expand Up @@ -197,18 +198,25 @@ def local_critical(*messages, support_hint=True, ret_code=1, **kwargs):
# @fixme: not the best solution
STDOUT_PRINT = False
local_print("listing all connected devices:")
from pynitrokey.cli import nitropy

nitropy.commands["list"].callback()
try:
from pynitrokey.cli import nitropy

nitropy.commands["list"].callback()
except Exception:
local_print("Unable to list devices. See log for the details.")
logger = logging.getLogger()
logger.exception("Unable to list devices")

STDOUT_PRINT = True

local_print(
"",
"-" * 80,
"Critical error occurred, exiting now",
"Unexpected? Is this a bug? Do you would like to get support/help?",
f"- You can report issues at: {GH_ISSUES_URL}",
f"- Writing an e-mail to: {SUPPORT_EMAIL} is also possible",
"Unexpected? Is this a bug? Would you like to get support/help?",
f"- You can report issues at: {SUPPORT_URL}",
f"- Writing an e-mail to {SUPPORT_EMAIL} is also possible",
f"- Please attach the log: '{LOG_FN}' with any support/help request!",
"-" * 80,
"",
Expand Down

0 comments on commit b11a6ac

Please sign in to comment.