From bbd8d60eb506c72ac604d17aead31e0a24a495bd Mon Sep 17 00:00:00 2001 From: viseshrp Date: Sun, 8 Dec 2024 18:34:40 -0500 Subject: [PATCH] improve exception handling --- src/ansys/dynamicreporting/core/serverless/adr.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ansys/dynamicreporting/core/serverless/adr.py b/src/ansys/dynamicreporting/core/serverless/adr.py index b4dc6e99..64e01c14 100644 --- a/src/ansys/dynamicreporting/core/serverless/adr.py +++ b/src/ansys/dynamicreporting/core/serverless/adr.py @@ -288,6 +288,8 @@ def backup_database( if database != "default" and database not in self._databases: raise ADRException(f"{database} must be configured first using the 'databases' option.") target_dir = Path(output_directory).resolve(strict=True) + if not target_dir.is_dir(): + raise InvalidPath(extra_detail=f"{output_directory} is not a valid directory.") # call django management command to dump the database timestamp = datetime.now().strftime("%Y%m%d%H%M%S") file_path = target_dir / f"backup_{timestamp}.json{'.gz' if compress else ''}" @@ -308,14 +310,14 @@ def backup_database( def restore_database(self, input_file: str, *, database: str = "default") -> None: if database != "default" and database not in self._databases: raise ADRException(f"{database} must be configured first using the 'databases' option.") - input_file = Path(input_file).resolve(strict=True) - if not input_file.is_file(): - raise InvalidPath(extra_detail=str(input_file)) + backup_file = Path(input_file).resolve(strict=True) + if not backup_file.is_file(): + raise InvalidPath(extra_detail=f"{input_file} is not a valid file.") # call django management command to load the database try: management.call_command( "loaddata", - str(input_file), + str(backup_file), "--database", database, "--ignorenonexistent",