From: Shane Jaroch Date: Tue, 13 Feb 2024 14:56:16 +0000 (-0500) Subject: wip bug report X-Git-Tag: v0.2.8.dev0~47 X-Git-Url: https://git.nutra.tk/v1?a=commitdiff_plain;h=f3b387d26b8f5a1009dda9dcee11b01dc4749c7c;p=nutratech%2Fcli.git wip bug report --- diff --git a/.editorconfig b/.editorconfig index 11b1d23..3d74d05 100644 --- a/.editorconfig +++ b/.editorconfig @@ -34,5 +34,5 @@ indent_size = 2 max_line_length = 79 -[{COMMIT_EDITMSG,MERGE_MSG,SQUASH_MSG,git-rebase-todo}] +[{COMMIT_EDITMSG,MERGE_MSG,SQUASH_MSG,TAG_EDITMSG,git-rebase-todo}] max_line_length = 72 diff --git a/ntclient/__main__.py b/ntclient/__main__.py index 99964c2..6de1e07 100644 --- a/ntclient/__main__.py +++ b/ntclient/__main__.py @@ -23,7 +23,7 @@ from ntclient import ( __version__, ) from ntclient.argparser import build_subcommands -from ntclient.utils import CLI_CONFIG +from ntclient.utils import CLI_CONFIG, handle_runtime_exception from ntclient.utils.exceptions import SqlException @@ -101,23 +101,19 @@ def main(args: list = None) -> int: # type: ignore exit_code, *_results = func(_parser) except SqlException as sql_exception: # pragma: no cover print("Issue with an sqlite database: " + repr(sql_exception)) - if CLI_CONFIG.debug: - raise + handle_runtime_exception(sql_exception) except HTTPError as http_error: # pragma: no cover err_msg = "{0}: {1}".format(http_error.code, repr(http_error)) print("Server response error, try again: " + err_msg) - if CLI_CONFIG.debug: - raise + handle_runtime_exception(http_error) except URLError as url_error: # pragma: no cover print("Connection error, check your internet: " + repr(url_error.reason)) - if CLI_CONFIG.debug: - raise + handle_runtime_exception(url_error) except Exception as exception: # pylint: disable=broad-except # pragma: no cover print("Unforeseen error, run with --debug for more info: " + repr(exception)) print("You can open an issue here: %s" % __url__) print("Or send me an email with the debug output: %s" % __email__) - if CLI_CONFIG.debug: - raise + handle_runtime_exception(exception) finally: if CLI_CONFIG.debug: exc_time = time.time() - start_time diff --git a/ntclient/argparser/__init__.py b/ntclient/argparser/__init__.py index d3a255b..b7299c0 100644 --- a/ntclient/argparser/__init__.py +++ b/ntclient/argparser/__init__.py @@ -23,6 +23,7 @@ def build_subcommands(subparsers: argparse._SubParsersAction) -> None: build_day_subcommand(subparsers) build_recipe_subcommand(subparsers) build_calc_subcommand(subparsers) + build_subcommand_bug(subparsers) ################################################################################ @@ -319,3 +320,10 @@ def build_calc_subcommand(subparsers: argparse._SubParsersAction) -> None: "ankle", type=float, nargs="?", help="ankle (cm) [casey_butt]" ) calc_lbl_parser.set_defaults(func=parser_funcs.calc_lbm_limits) + + +def build_subcommand_bug(subparsers: argparse._SubParsersAction) -> None: + """Report bugs""" + + bug_parser = subparsers.add_parser("bug", help="report bugs") + bug_parser.set_defaults(func=parser_funcs.bugs_report) diff --git a/ntclient/argparser/funcs.py b/ntclient/argparser/funcs.py index fb4e753..fbeb8e7 100644 --- a/ntclient/argparser/funcs.py +++ b/ntclient/argparser/funcs.py @@ -335,3 +335,9 @@ def calc_lbm_limits(args: argparse.Namespace) -> tuple: print(_table) return 0, result + + +def bugs_report() -> tuple: + """Report a bug""" + n_submissions = ntclient.services.bugs.submit() + return 0, n_submissions diff --git a/ntclient/ntsqlite b/ntclient/ntsqlite index e69368f..939f550 160000 --- a/ntclient/ntsqlite +++ b/ntclient/ntsqlite @@ -1 +1 @@ -Subproject commit e69368ff9a64db7134a212686c08922c6537bcee +Subproject commit 939f55077b97bd1fe1c8e2b897b032dbc1564487 diff --git a/ntclient/services/bugs.py b/ntclient/services/bugs.py new file mode 100644 index 0000000..b29e6c1 --- /dev/null +++ b/ntclient/services/bugs.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue Feb 13 09:51:48 2024 + +@author: shane +""" diff --git a/ntclient/utils/__init__.py b/ntclient/utils/__init__.py index 042f66f..f5fc7b0 100644 --- a/ntclient/utils/__init__.py +++ b/ntclient/utils/__init__.py @@ -150,3 +150,12 @@ def activity_factor_from_index(activity_factor: int) -> float: raise ValueError( # pragma: no cover "No such ActivityFactor for value: %s" % activity_factor ) + + +def handle_runtime_exception(exception: Exception) -> None: + """ + Handles exceptions raised during runtime. + """ + print("Exception: %s" % exception) + if CLI_CONFIG.debug: + raise exception