objectstore: runtime exceptions for mount errors

Instead if using `check=True` for `subprocess.run`, which turns
a process failure (i.e. non-zero return codes) into generic a
`CalledProcessError` exception, use `check=False` and explicitly
handle mount errors, translating them into a `RuntimeError` with
a better error message.
This commit is contained in:
Christian Kellner 2021-06-01 10:20:52 +00:00 committed by Tom Gundersen
parent f8428e56e2
commit 1743eceb41

View file

@ -31,7 +31,17 @@ def mount(source, target, bind=True, ro=True, private=True, mode="0755"):
args += ["--make-private"]
if options:
args += ["-o", ",".join(options)]
subprocess.run(["mount"] + args + [source, target], check=True)
r = subprocess.run(["mount"] + args + [source, target],
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
encoding="utf-8",
check=False)
if r.returncode != 0:
code = r.returncode
msg = r.stdout.strip()
raise RuntimeError(f"{msg} (code: {code})")
def umount(target, lazy=True):