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:
parent
f8428e56e2
commit
1743eceb41
1 changed files with 11 additions and 1 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue