Skip to content

Commit 37d25da

Browse files
committed
Catch IOException: Cannot run program
1 parent eafd736 commit 37d25da

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

modules/options/src/main/scala/scala/build/options/ComputeVersion.scala

+11-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import scala.build.Positioned
99
import scala.build.errors.{BuildException, MalformedInputError}
1010
import scala.io.Codec
1111
import scala.jdk.CollectionConverters.*
12-
import scala.util.Using
12+
import scala.util.{Success, Try, Using}
1313

1414
sealed abstract class ComputeVersion extends Product with Serializable {
1515
def get(workspace: os.Path): Either[BuildException, String]
@@ -19,11 +19,16 @@ object ComputeVersion {
1919

2020
final case class Command(command: Seq[String]) extends ComputeVersion {
2121
def get(workspace: os.Path): Either[BuildException, String] = {
22-
val res = os.proc(command).call(stdin = os.Inherit, cwd = workspace, check = false)
23-
if (res.exitCode == 0)
24-
Right(res.out.trim(Codec.default))
25-
else
26-
Left(new Command.ComputeVersionCommandError(command, res.exitCode))
22+
val maybeRes = Try(os.proc(command).call(stdin = os.Inherit, cwd = workspace, check = false))
23+
maybeRes match {
24+
case Success(res) if res.exitCode == 0 =>
25+
Right(res.out.trim(Codec.default))
26+
case _ =>
27+
Left(new Command.ComputeVersionCommandError(
28+
command,
29+
maybeRes.map(_.exitCode).getOrElse(1)
30+
))
31+
}
2732
}
2833
}
2934

0 commit comments

Comments
 (0)