From 6e61a74250dd1489e75a592149e7bbdd1fbb766c Mon Sep 17 00:00:00 2001 From: Lea Laux Date: Wed, 3 Mar 2021 11:55:41 +0100 Subject: [PATCH] Catch error in file remove process Catch an error in the file removing process after a database dump for windows users (issue #40) --- pygadmin/database_dumper.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pygadmin/database_dumper.py b/pygadmin/database_dumper.py index 6d8a399..19b2890 100644 --- a/pygadmin/database_dumper.py +++ b/pygadmin/database_dumper.py @@ -73,12 +73,20 @@ class DatabaseDumper: # If an exception occurs, for example triggered by a timeout, save a message in the log. except Exception as error: - logging.error("An error occurred during the dumping process: {}".format(error)) + logging.error("An error occurred during the dumping process: {}".format(error), exc_info=True) # Use a finally block for a short clean up. finally: - # Remove the file, which was used for submitting the password and is no longer necessary. - os.remove(file_path) + # Try to remove the file. Use a try statement, because this block can cause errors for windows user. + try: + # Remove the file, which was used for submitting the password and is no longer necessary. + os.remove(file_path) + + # Add the exception to the log. + except Exception as error: + logging.error("An error occurred during the clean up process of the database dump: {}".format( + error), exc_info=True) + # Return the result. return result