From 154ed8502ce35a2ac5338b6fb2b4fcdac1ac4b42 Mon Sep 17 00:00:00 2001 From: masc3d Date: Mon, 9 May 2016 17:32:09 +0200 Subject: [PATCH] RESOLVED #18, Improve error output UPDATED version to 0.6.5 --- btrfs_sxbackup/__init__.py | 2 +- btrfs_sxbackup/core.py | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/btrfs_sxbackup/__init__.py b/btrfs_sxbackup/__init__.py index 4c5e4a7..3190f6e 100644 --- a/btrfs_sxbackup/__init__.py +++ b/btrfs_sxbackup/__init__.py @@ -5,7 +5,7 @@ # Software Foundation; either version 2 of the License, or (at your option) # any later version. -__version__ = '0.6.4' +__version__ = '0.6.5' __author__ = 'Marco Schindler' __email__ = 'masc@disappear.de' __maintainer__ = 'masc@disappear.de' diff --git a/btrfs_sxbackup/core.py b/btrfs_sxbackup/core.py index f5a603d..28e3523 100644 --- a/btrfs_sxbackup/core.py +++ b/btrfs_sxbackup/core.py @@ -138,6 +138,9 @@ def _log_info(self, msg): def _log_warn(self, msg): self.__logger.warn(self._format_log_msg(msg)) + def _log_error(self, msg): + self.__logger.error(self._format_log_msg(msg)) + def _log_debug(self, msg): self.__logger.debug(self._format_log_msg(msg)) @@ -294,14 +297,20 @@ def transfer_btrfs_snapshot(self, # Wait for commands to complete send_returncode = send_process.wait() receive_returncode = receive_process.wait() - if send_returncode: - raise subprocess.CalledProcessError(send_process.returncode, - send_process.args, - send_process.stderr.read()) + + def log_process_error(proc_returncode, proc_args, proc_out): + proc_out_fmt = proc_out.read().decode().strip() + self._log_error('Command %s failed with error code %d (%s)' + % (proc_args, proc_returncode, proc_out_fmt)) + if receive_returncode: - raise subprocess.CalledProcessError(receive_process.returncode, - receive_process.args, - receive_process.stdout.read()) + log_process_error(receive_process.returncode, receive_process.args, receive_process.stdout) + + if send_returncode: + log_process_error(send_process.returncode, send_process.args, send_process.stderr) + + if receive_returncode or send_returncode: + raise Error("Transferring snapshot failed") except BaseException as e: try: