Take advantage of the return of the mutated exception
authorKarl O. Pinc <kop@karlpinc.com>
Tue, 19 Jan 2021 18:50:00 +0000 (12:50 -0600)
committerKarl O. Pinc <kop@karlpinc.com>
Tue, 19 Jan 2021 18:50:00 +0000 (12:50 -0600)
src/pgwui_bulk_upload/views/bulk_upload.py

index 1043d7f36a4e29b60fc6ce9c50de2bc9c39c330e..23aced1065ca2a835fc35515460d85d99af297eb 100644 (file)
@@ -116,15 +116,13 @@ class SaveBulkLine(DataLineProcessor, ParameterExecutor):
             self.param_execute(self.insert_map[filepath], udl)
         except (core_ex.DataLineError, core_ex.DBError) as exp:
             relation = data.relation
-            exp.color(map_description(filepath, relation),
-                      filepath, relation)
-            raise exp
+            raise exp.color(map_description(filepath, relation),
+                            filepath, relation)
         except psycopg2.DatabaseError as exp:
             relation = data.relation
-            myexp = core_ex.DBDataLineError(udl, exp)
-            myexp.color(map_description(filepath, relation),
-                        filepath, relation)
-            raise myexp
+            raise core_ex.DBDataLineError(udl, exp).color(
+                map_description(filepath, relation),
+                filepath, relation)
 
 
 class UploadBulkData(UploadData):
@@ -334,9 +332,8 @@ class UploadDir():
                                                    trim=uf['trim_upload']))
                 except core_ex.PGWUIError as exp:
                     relation = fmap['relation']
-                    exp.color(map_description(name, relation),
-                              name, relation)
-                    errors.append(exp)
+                    errors.append(exp.color(map_description(name, relation),
+                                            name, relation))
         if errors:
             raise core_ex.MultiError(errors)
         return filedata
@@ -562,10 +559,10 @@ class BulkTableUploadHandler(BaseTableUploadHandler):
                     try:
                         self.cur.execute('ROLLBACK;')
                     except psycopg2.DatabaseError as exp:
-                        err = ex.CannotRollbackError(exp)
-                        err.color(map_description(fileinfo.filepath,
-                                                  fileinfo.relation),
-                                  fileinfo.filepath, fileinfo.relation)
+                        err = ex.CannotRollbackError(exp).color(
+                            map_description(fileinfo.filepath,
+                                            fileinfo.relation),
+                            fileinfo.filepath, fileinfo.relation)
                         errors.append(err)
                     in_trans = False
             finally: