Handle multiple errors from a get_data or factory or cleanup
authorKarl O. Pinc <kop@karlpinc.com>
Wed, 23 Dec 2020 17:24:07 +0000 (11:24 -0600)
committerKarl O. Pinc <kop@karlpinc.com>
Thu, 24 Dec 2020 22:35:57 +0000 (16:35 -0600)
src/pgwui_core/core.py
src/pgwui_core/exceptions.py

index f4cc3f93d83f920e0d5e98a134dd2063ca62a44a..6f60d67f2d06e8fb14bdbe71233a6023a5cf4c59 100644 (file)
@@ -1046,6 +1046,10 @@ class DBHandler(object):
         (Post-processing is referred to as "cleanup" presently.)
       Rendering the html output
 
+    The get_data, factory, and cleanup have two possible ways to report errors.
+    They can raise an exception or raise the "special" exception
+    MultiError.
+
     Attributes:
       request       A pyramid request instance
       uf            An UploadForm instance
@@ -1076,6 +1080,8 @@ class DBHandler(object):
         '''
         Validate input needed beyond that required to connect to the db.
 
+        Returns a list of exceptions
+
         Note that this occurs after read() is called.
 
         This is expected to be replaced by it's subclass.
@@ -1104,6 +1110,9 @@ class DBHandler(object):
         '''
         Called after all lines are processed to do any final
         updates to the db.
+
+        May raise a single exception or may save multiple exceptions
+        and raise MultiError.
         '''
         pass
 
@@ -1175,6 +1184,7 @@ class UploadHandler(SessionDBHandler):
         '''
         Takes an UploadEngine instance
         Returns a DataLineProcessor instance
+        May raise a single exception or MultiError.
         '''
         raise NotImplementedError
 
@@ -1411,6 +1421,8 @@ class DBConnector(object):
             # (Cannot call uh until after self is fully
             # initalized, including self.cur.)
             processor = self.uh.factory(self)
+        except core_ex.MultiError as ex:
+            errors.extend(ex.errors)
         except core_ex.Error as ex:
             errors.append(ex)
         else:
@@ -1419,6 +1431,8 @@ class DBConnector(object):
                 # Let upload handler finish
                 try:
                     self.uh.cleanup()
+                except core_ex.MultiError as ex:
+                    errors.extend(ex.errors)
                 except core_ex.UploadError as ex:
                     errors.append(ex)
             finally:
index 1d920317603fa1b89d6a32ff95a6c53e089c0eba..dc89a4c9d6b36b0f0bfd28bfd261e9a82d4c4c63 100644 (file)
@@ -30,6 +30,13 @@ class PGWUIError(Exception):
     pass
 
 
+class MultiError(PGWUIError):
+    '''Multiple errors
+    '''
+    def __init__(self, errors):
+        self.errors = errors
+
+
 class UploadError(PGWUIError):
     '''
     Module exceptions are derived from this class.