]> Nutra Git (v2) - nutratech/cli.git/commitdiff
wip bug report
authorShane Jaroch <chown_tee@proton.me>
Tue, 13 Feb 2024 19:45:42 +0000 (14:45 -0500)
committerShane Jaroch <chown_tee@proton.me>
Tue, 13 Feb 2024 19:45:42 +0000 (14:45 -0500)
ntclient/argparser/funcs.py
ntclient/services/bugs.py
ntclient/utils/sql.py

index fbeb8e76c3e2dddc601ff790692bd582bb3d5a3a..ada945e497b1e40217a272b446100120868ead36 100644 (file)
@@ -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
index efd99c71d6c1bd219c559666dab2086dc4dac8f6..0b32a1164438e7407660c57206eb2c72b8b1c4b9 100644 (file)
@@ -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:
index 2c3a151af7323454e4a128b7c91d294d70aa58bb..d19134fe1daada30e5135847093d3055701732bb 100644 (file)
@@ -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