Skip to content

Commit bcf6007

Browse files
committed
Bugfix: Catch illegal state on parse of Python version
1 parent 8fca3ea commit bcf6007

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/main/PythonExtension.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,21 @@ object PythonBinary {
271271
Option(new BufferedReader(new InputStreamReader(proc.getInputStream)).readLine()).orElse(
272272
Option(new BufferedReader(new InputStreamReader(proc.getErrorStream)).readLine())
273273
).flatMap { verString =>
274-
val m = """Python (\d+)\.(\d+)\.(\d+)""".r.findAllIn(verString)
275-
if (m.groupCount == 3) Some(PythonBinary(f, (m.group(1).toInt, m.group(2).toInt, m.group(3).toInt)))
276-
else None
274+
parsePythonVersion(verString).map({ case (version) => PythonBinary(f, version) })
277275
}
278276
} catch {
279277
case _: IOException => None
278+
case _: IllegalStateException => None
280279
case _: SecurityException => None
281280
}
282281
}
282+
283+
def parsePythonVersion(v: String): Option[(Int, Int, Int)] = {
284+
val m = """Python (\d+)\.(\d+)\.(\d+)""".r.findAllIn(v)
285+
if (m.groupCount == 3) {
286+
Some(m.group(1).toInt, m.group(2).toInt, m.group(3).toInt)
287+
} else {
288+
None
289+
}
290+
}
283291
}

0 commit comments

Comments
 (0)