Skip to content

Commit

Permalink
jvm_version: handle CalledProcessError
Browse files Browse the repository at this point in the history
The function is supposed to raise RuntimeError, not CalledProcessError,
if the version cannot be determined. See also imagej/pyimagej#237.
  • Loading branch information
ctrueden committed Nov 18, 2022
1 parent 7528653 commit 4409ef3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/scyjava/_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,13 @@ def jvm_version() -> str:
if java is None:
raise RuntimeError(f"No java executable found inside: {p}")

output = subprocess.check_output(
[str(java), "-version"], stderr=subprocess.STDOUT
).decode()
try:
output = subprocess.check_output(
[str(java), "-version"], stderr=subprocess.STDOUT
).decode()
except subprocess.CalledProcessError as e:
raise RuntimeError("System call to java failed") from e

m = re.match('.*version "(([0-9]+\\.)+[0-9]+)', output)
if not m:
raise RuntimeError(f"Inscrutable java command output:\n{output}")
Expand Down

0 comments on commit 4409ef3

Please sign in to comment.