From aae959cd6d56b9dbe7bc58526e381c8e707839d6 Mon Sep 17 00:00:00 2001 From: kmille Date: Sun, 7 Jan 2024 00:02:43 +0100 Subject: [PATCH] borg with-lock: catch exception, print error msg, fixes #8022 --- src/borg/archiver.py | 2 ++ src/borg/testsuite/archiver.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/src/borg/archiver.py b/src/borg/archiver.py index 0110d6342..a63ac1ea8 100644 --- a/src/borg/archiver.py +++ b/src/borg/archiver.py @@ -1806,6 +1806,8 @@ class Archiver: # we exit with the return code we get from the subprocess rc = subprocess.call([args.command] + args.args, env=env) set_ec(rc) + except (FileNotFoundError, OSError, ValueError) as e: + raise CommandError(f"Error while trying to run '{args.command}': {e}") finally: # we need to commit the "no change" operation we did to the manifest # because it created a new segment file in the repository. if we would diff --git a/src/borg/testsuite/archiver.py b/src/borg/testsuite/archiver.py index 1d36d4808..fff814d19 100644 --- a/src/borg/testsuite/archiver.py +++ b/src/borg/testsuite/archiver.py @@ -3215,6 +3215,11 @@ class ArchiverTestCase(ArchiverTestCaseBase): cmd = 'python3', '-c', 'import os, sys; sys.exit(42 if os.path.exists("%s") else 23)' % lock_path self.cmd('with-lock', self.repository_location, *cmd, fork=True, exit_code=42) + def test_with_lock_non_existent_command(self): + self.cmd('init', '--encryption=repokey', self.repository_location) + cmd = ['non_existent_command', ] + self.cmd('with-lock', self.repository_location, *cmd, fork=True, exit_code=EXIT_ERROR) + def test_recreate_list_output(self): self.cmd('init', '--encryption=repokey', self.repository_location) self.create_regular_file('file1', size=0)