From: Shane Jaroch Date: Tue, 13 Feb 2024 19:45:42 +0000 (-0500) Subject: wip bug report X-Git-Tag: v0.2.8.dev0~45 X-Git-Url: https://git.nutra.tk/v1?a=commitdiff_plain;h=17ef5610d207d189c1bb18edbd3037015ce8785d;p=nutratech%2Fcli.git wip bug report --- diff --git a/ntclient/argparser/funcs.py b/ntclient/argparser/funcs.py index fbeb8e7..ada945e 100644 --- a/ntclient/argparser/funcs.py +++ b/ntclient/argparser/funcs.py @@ -14,6 +14,7 @@ import traceback from tabulate import tabulate import ntclient.services.analyze +import ntclient.services.bugs import ntclient.services.recipe.utils import ntclient.services.usda from ntclient.services import calculate as calc diff --git a/ntclient/services/bugs.py b/ntclient/services/bugs.py index efd99c7..0b32a11 100644 --- a/ntclient/services/bugs.py +++ b/ntclient/services/bugs.py @@ -6,6 +6,7 @@ Created on Tue Feb 13 09:51:48 2024 @author: shane """ import os +import sqlite3 import traceback import ntclient.services.api.funcs @@ -14,24 +15,33 @@ from ntclient.persistence.sql.nt import sql as sql_nt def insert(args: list, exception: Exception) -> None: """Insert bug report into nt.sqlite3, return True/False.""" - print("inserting bug reports...", end="") - sql_nt( - """ + print("INFO: inserting bug report...") + try: + sql_nt( + """ INSERT INTO bug (profile_id, arguments, repr, stack, client_info, app_info, user_details) - VALUES - (?,?,?,?,?,?,?) - """, - ( - 1, - " ".join(args), - repr(exception), - os.linesep.join(traceback.format_tb(exception.__traceback__)), - "client_info", - "app_info", - "user_details", - ), - ) + VALUES + (?,?,?,?,?,?,?) + """, + ( + 1, + " ".join(args), + repr(exception), + os.linesep.join(traceback.format_tb(exception.__traceback__)), + "client_info", + "app_info", + "user_details", + ), + ) + except sqlite3.IntegrityError as exc: + print(f"WARN: {repr(exc)}") + if repr(exc) == ( + "IntegrityError('UNIQUE constraint failed: " "bug.arguments, bug.stack')" + ): + print("INFO: bug report already exists") + else: + raise def submit() -> int: diff --git a/ntclient/utils/sql.py b/ntclient/utils/sql.py index 2c3a151..d19134f 100644 --- a/ntclient/utils/sql.py +++ b/ntclient/utils/sql.py @@ -13,7 +13,7 @@ def handle_runtime_exception(args: list, exception: Exception) -> None: """ Handles exceptions raised during runtime. """ - print("Exception: %s" % exception) + print("ERROR: Exception: %s" % exception) + bug_insert(args, exception) if CLI_CONFIG.debug: - bug_insert(args, exception) raise exception