Trap and report errors from the csv module
authorKarl O. Pinc <kop@karlpinc.com>
Sun, 29 Sep 2024 22:14:09 +0000 (17:14 -0500)
committerKarl O. Pinc <kop@karlpinc.com>
Sun, 29 Sep 2024 22:14:09 +0000 (17:14 -0500)
src/pgwui_sql/exceptions.py
src/pgwui_sql/views/sql.py

index 99c558bcbdf8eede44378131fdb37bd6f7c880ef..3a8d532109aa4efb5d09340b1effb3df714fb9c5 100644 (file)
@@ -70,3 +70,15 @@ class NoStatementsError(SQLError):
     '''
     def __init__(self, descr='', detail=''):
         super().__init__('Notice', '', descr=descr, detail=detail)
+
+
+class CSVError(SQLError):
+    '''
+    Error raised when the csv module raises an error
+
+    descr  More description of the error
+    detail Extra HTML describing the error
+    '''
+    def __init__(self, descr='', detail=''):
+        super().__init__('Error while formatting the download',
+                         '', descr=descr, detail=detail)
index cdc2fe22c5e7e598431cf037445898a5fa047799..9c1d07767f3c06e23ce1ad1054301aaa16161eac 100644 (file)
@@ -325,7 +325,10 @@ class SQLResultsHandler(pgwui_core.core.SessionDBHandler):
             sql_results.append(sql_result)
             nextset = cur.nextset()
 
-        self.make_download(sql_results)
+        try:
+            self.make_download(sql_results)
+        except csv.Error as ex:
+            raise sql_ex.CSVError(descr=f'The csv module reports: {ex}')
 
     def factory(self, ue):
         '''Make a db loader function from an UploadEngine.