From a76169be27ddea48aa09efdc138b33c06bd3552e Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Tue, 27 Apr 2021 15:33:28 -0500 Subject: [PATCH] pgwui_core.exceptions.Error is now SetupError --- src/pgwui_bulk_upload/exceptions.py | 26 ++++++++----------- .../templates/bulk_upload.mak | 4 +-- src/pgwui_bulk_upload/views/bulk_upload.py | 2 +- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/pgwui_bulk_upload/exceptions.py b/src/pgwui_bulk_upload/exceptions.py index 7a06eae..c34e24d 100644 --- a/src/pgwui_bulk_upload/exceptions.py +++ b/src/pgwui_bulk_upload/exceptions.py @@ -20,6 +20,8 @@ # Karl O. Pinc from pgwui_core import exceptions as core_ex +# PGWUI setting related exceptions +from pgwui_core.exceptions import SetupError # Line-by-line processing errors @@ -32,22 +34,16 @@ class CannotReReadError(core_ex.DataLineError): f'The error is: {exp}') -# PGWUI setting related exceptions - -class Error(core_ex.Error): - pass - - # Exceptions that require detail -class NotAZipfileError(Error): +class NotAZipfileError(SetupError): def __init__(self, filename): super().__init__( 'No zip file uploaded', f'The uploaded file ({filename}) is not recognized as a zip file') -class CannotUnarchiveError(Error): +class CannotUnarchiveError(SetupError): def __init__(self, filename, err): super().__init__( 'Cannot unzip', @@ -55,7 +51,7 @@ class CannotUnarchiveError(Error): 'the error reported is: err')) -class NotADirectoryError(Error): +class NotADirectoryError(SetupError): def __init__(self, filename, name): super().__init__( 'Not a directory', @@ -64,14 +60,14 @@ class NotADirectoryError(Error): 'The entries at the top of the zip file must be directories') -class EmptyArchiveError(Error): +class EmptyArchiveError(SetupError): def __init__(self, filename, err): super().__init__( 'Empty zip file', f'The uploaded file ({filename}) has no content') -class NotAFileError(Error): +class NotAFileError(SetupError): def __init__(self, filename, name): super().__init__( 'Not a file', @@ -80,7 +76,7 @@ class NotAFileError(Error): 'The directories in the zip file may only contain files') -class NoMapfileError(Error): +class NoMapfileError(SetupError): def __init__(self, filename, map_file): super().__init__( 'Missing map file', @@ -90,14 +86,14 @@ class NoMapfileError(Error): 'maps file names to table names') -class CannotReadError(Error): +class CannotReadError(SetupError): def __init__(self, filename, exp): super().__init__( f'Cannot open ({filename}) for reading', f'The error is: {exp}') -class CannotRollbackError(Error): +class CannotRollbackError(SetupError): def __init__(self, exp): super().__init__( 'Cannot roll back the current transaction', @@ -107,7 +103,7 @@ class CannotRollbackError(Error): f'The error from psycopg2 is: ({exp})') -class BadMapFileError(Error): +class BadMapFileError(SetupError): pass diff --git a/src/pgwui_bulk_upload/templates/bulk_upload.mak b/src/pgwui_bulk_upload/templates/bulk_upload.mak index ada7b8d..453ca7b 100644 --- a/src/pgwui_bulk_upload/templates/bulk_upload.mak +++ b/src/pgwui_bulk_upload/templates/bulk_upload.mak @@ -31,7 +31,7 @@ <%! from pgwui_upload_core.template_utils import show_choice from pgwui_common.path import asset_abspath - import pgwui_core.exceptions as core_ex + import pgwui_common.exceptions as common_ex upload_base_mak = asset_abspath('pgwui_upload_core:templates/upload.mak') %> @@ -93,7 +93,7 @@ last_filepath = None f_errors = [] for error in errors: - if isinstance(error, core_ex.UploadError): + if isinstance(error, common_ex.UploadError): if error.filepath != last_filepath: if last_filepath: self.file_errors(f_errors, last_filepath, firsterr) diff --git a/src/pgwui_bulk_upload/views/bulk_upload.py b/src/pgwui_bulk_upload/views/bulk_upload.py index c456908..922ba1a 100644 --- a/src/pgwui_bulk_upload/views/bulk_upload.py +++ b/src/pgwui_bulk_upload/views/bulk_upload.py @@ -419,7 +419,7 @@ class UploadArchive(): try: # Every file consumes a header line self.lineno += updir.open(zip_root / dentry.name) - except ex.Error as exp: + except ex.SetupError as exp: err_tups.append((dentry.name, exp)) except core_ex.MultiError as exp: err_tups.extend([(dentry.name, err) for err in exp.errors]) -- 2.34.1