Skip to content

Commit

Permalink
Merge pull request #8100 from ThomasWaldmann/fix-with-lock-exceptions…
Browse files Browse the repository at this point in the history
…-master

borg with-lock: catch exception, print error msg, fixes #8022
  • Loading branch information
ThomasWaldmann committed Feb 18, 2024
2 parents ad3f136 + 1f5cc35 commit 74129e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/borg/archiver/lock_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ._common import with_repository
from ..cache import Cache
from ..constants import * # NOQA
from ..helpers import prepare_subprocess_env, set_ec
from ..helpers import prepare_subprocess_env, set_ec, CommandError
from ..manifest import Manifest

from ..logger import create_logger
Expand Down Expand Up @@ -35,6 +35,8 @@ def do_with_lock(self, args, repository):
# 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
Expand Down
7 changes: 7 additions & 0 deletions src/borg/testsuite/archiver/lock_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ def test_with_lock(archivers, request):
lock_path = os.path.join(archiver.repository_path, "lock.exclusive")
command = "python3", "-c", 'import os, sys; sys.exit(42 if os.path.exists("%s") else 23)' % lock_path
cmd(archiver, "with-lock", *command, fork=True, exit_code=42)


def test_with_lock_non_existent_command(archivers, request):
archiver = request.getfixturevalue(archivers)
cmd(archiver, "rcreate", RK_ENCRYPTION)
command = ["non_existent_command"]
cmd(archiver, "with-lock", *command, fork=True, exit_code=EXIT_ERROR)

0 comments on commit 74129e5

Please sign in to comment.