Skip to content

Commit

Permalink
Merge pull request #615 from ScilifelabDataCentre/DDS-1484-error-code…
Browse files Browse the repository at this point in the history
…-to-be-returned-from-cli-if-any-error

Return exit code 1 if only partial upload
  • Loading branch information
i-oden authored Mar 6, 2023
2 parents 8db3f1e + 10181a0 commit 733ffd6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([#615](https://github.com/ScilifelabDataCentre/dds_cli/pull/615))
6 changes: 5 additions & 1 deletion dds_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
22 changes: 14 additions & 8 deletions dds_cli/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ 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"
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.
Expand All @@ -218,16 +224,16 @@ 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 exception in order to give exit code 1
raise exceptions.PartialUploadException(
f"{nr_uploaded} files were already uploaded.\nUpload [bold]partially[/bold] completed!\n"
)

else:
Expand Down
4 changes: 4 additions & 0 deletions dds_cli/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down

0 comments on commit 733ffd6

Please sign in to comment.