From 4d284e7a021bf01109e6cc373494be3329f700de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ina=20Od=C3=A9n=20=C3=96sterbo?= Date: Tue, 28 Feb 2023 14:59:06 +0100 Subject: [PATCH 1/3] raise partialuploadexception --- CHANGELOG.md | 4 ++++ dds_cli/__main__.py | 6 +++++- dds_cli/base.py | 20 ++++++++++++-------- dds_cli/exceptions.py | 4 ++++ 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16c7bba4b..275b93200 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -241,3 +241,7 @@ Please add a _short_ line describing the PR you make, if the PR implements a spe - Logging: Reduce debug level logging and remove logging from root ([#606](https://github.com/ScilifelabDataCentre/dds_cli/pull/606)) - Add separate executables for Ubuntu latest (currently 22.04) and Ubuntu 20.04 ([#604](https://github.com/ScilifelabDataCentre/dds_cli/pull/604)) - Bug: PyInstaller command not valid for Linux and macOS ([#612](https://github.com/ScilifelabDataCentre/dds_cli/pull/612)) + +# Sprint (2023-02-17 - 2023-03-03) + +- Bug: Return error code if not all files have been uploaded ([]()) diff --git a/dds_cli/__main__.py b/dds_cli/__main__.py index a6c88bd5a..15ea7c13a 100644 --- a/dds_cli/__main__.py +++ b/dds_cli/__main__.py @@ -1612,8 +1612,12 @@ def put_data( dds_cli.exceptions.ApiRequestError, dds_cli.exceptions.NoKeyError, dds_cli.exceptions.NoDataError, + dds_cli.exceptions.PartialUploadException, ) as err: - LOG.error(err) + if isinstance(err, dds_cli.exceptions.PartialUploadException): + LOG.warning(err) + else: + LOG.error(err) sys.exit(1) diff --git a/dds_cli/base.py b/dds_cli/base.py index 3b01b60e9..8d732123d 100644 --- a/dds_cli/base.py +++ b/dds_cli/base.py @@ -210,6 +210,11 @@ def __printout_delivery_summary(self): "specifying the same options as you did now. To also overwrite the files " "that were uploaded, also add the `--overwrite` flag at the end of the command." ) + raise exceptions.UploadError( + f"{intro_error_message}. \n" + f"{retry_message} \n\n" + f"See {self.failed_delivery_log} for more information." + ) else: # TODO: --destination should be able to >at least< overwrite the files in the # previously created download location. @@ -218,16 +223,15 @@ def __printout_delivery_summary(self): "specifying the same options as you did now. A new directory will " "automatically be created and all files will be downloaded again." ) - - dds_cli.utils.stderr_console.print( - f"{intro_error_message}. \n" - f"{retry_message} \n\n" - f"See {self.failed_delivery_log} for more information." - ) + dds_cli.utils.stderr_console.print( + f"{intro_error_message}. \n" + f"{retry_message} \n\n" + f"See {self.failed_delivery_log} for more information." + ) elif nr_uploaded: - dds_cli.utils.console.print( - (f"\nUpload completed!\n{nr_uploaded} files were already uploaded.\n") + raise exceptions.PartialUploadException( + f"{nr_uploaded} files were already uploaded.\nUpload [bold]partially[/bold] completed!\n" ) else: diff --git a/dds_cli/exceptions.py b/dds_cli/exceptions.py index 0fcd1d8ec..db6a54a3f 100644 --- a/dds_cli/exceptions.py +++ b/dds_cli/exceptions.py @@ -101,6 +101,10 @@ class UploadError(Exception): """Errors relating to file uploads.""" +class PartialUploadException(Exception): + """Exception raised when some files failed to upload.""" + + class DownloadError(Exception): """Errors relating to file download.""" From f5cac7df6a340019f43ecc17649a52aa513ad25e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ina=20Od=C3=A9n=20=C3=96sterbo?= Date: Tue, 28 Feb 2023 15:02:37 +0100 Subject: [PATCH 2/3] black --- CHANGELOG.md | 2 +- dds_cli/exceptions.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 275b93200..50b475356 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -244,4 +244,4 @@ Please add a _short_ line describing the PR you make, if the PR implements a spe # Sprint (2023-02-17 - 2023-03-03) -- Bug: Return error code if not all files have been uploaded ([]()) +- Bug: Return error code if not all files have been uploaded ([#615](https://github.com/ScilifelabDataCentre/dds_cli/pull/615)) diff --git a/dds_cli/exceptions.py b/dds_cli/exceptions.py index db6a54a3f..9431cf0e2 100644 --- a/dds_cli/exceptions.py +++ b/dds_cli/exceptions.py @@ -103,8 +103,8 @@ class UploadError(Exception): class PartialUploadException(Exception): """Exception raised when some files failed to upload.""" - - + + class DownloadError(Exception): """Errors relating to file download.""" From 10181a0f58224e911fa1194e3d11e3eb9762ebd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ina=20Od=C3=A9n=20=C3=96sterbo?= Date: Tue, 28 Feb 2023 15:04:30 +0100 Subject: [PATCH 3/3] comments --- dds_cli/base.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dds_cli/base.py b/dds_cli/base.py index 8d732123d..06e875fe7 100644 --- a/dds_cli/base.py +++ b/dds_cli/base.py @@ -210,6 +210,7 @@ def __printout_delivery_summary(self): "specifying the same options as you did now. To also overwrite the files " "that were uploaded, also add the `--overwrite` flag at the end of the command." ) + # Raise exception in order to give exit code 1 raise exceptions.UploadError( f"{intro_error_message}. \n" f"{retry_message} \n\n" @@ -230,6 +231,7 @@ def __printout_delivery_summary(self): ) elif nr_uploaded: + # Raise exception in order to give exit code 1 raise exceptions.PartialUploadException( f"{nr_uploaded} files were already uploaded.\nUpload [bold]partially[/bold] completed!\n" )