Skip to content

Commit 0f10f91

Browse files
committed
blooprifle: report exit code in exception
To help debugging, the failure code is now part of the exception in case the bloop server failed to start.
1 parent f0e6e9b commit 0f10f91

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

modules/bloop-rifle/src/main/scala/scala/build/blooprifle/FailedToStartServerException.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@ package scala.build.blooprifle
22

33
import scala.concurrent.duration.Duration
44

5-
final class FailedToStartServerException(timeoutOpt: Option[Duration] = None)
6-
extends Exception("Server didn't start" + timeoutOpt.fold("")(t => s" after $t"))
5+
abstract class FailedToStartServerException(message: String)
6+
extends Exception(message)
7+
8+
final class FailedToStartServerExitCodeException(exitCode: Int)
9+
extends FailedToStartServerException(f"Server failed with exit code $exitCode")
10+
11+
final class FailedToStartServerTimeoutException(timeout: Duration)
12+
extends FailedToStartServerException(f"Server didn't start after $timeout")

modules/bloop-rifle/src/main/scala/scala/build/blooprifle/internal/Operations.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import java.nio.file.{Files, Path, Paths}
1313
import java.util.concurrent.atomic.AtomicBoolean
1414
import java.util.concurrent.{ExecutorService, ScheduledExecutorService, ScheduledFuture}
1515

16-
import scala.build.blooprifle.{BloopRifleConfig, BloopRifleLogger, BspConnection, BspConnectionAddress, FailedToStartServerException}
16+
import scala.build.blooprifle.{BloopRifleConfig, BloopRifleLogger, BspConnection, BspConnectionAddress, FailedToStartServerExitCodeException, FailedToStartServerTimeoutException}
1717
import scala.concurrent.duration._
1818
import scala.concurrent.{Await, Future, Promise}
1919
import scala.util.control.NonFatal
@@ -247,11 +247,11 @@ object Operations {
247247
}
248248
val completionOpt =
249249
if (!p.isAlive() && exitCode != serverAlreadyRunningExitCode)
250-
Some(Failure(new FailedToStartServerException))
250+
Some(Failure(new FailedToStartServerExitCodeException(exitCode)))
251251
else if (check(address, logger))
252252
Some(Success(()))
253253
else if (timeout.isFinite && System.currentTimeMillis() - start > timeout.toMillis)
254-
Some(Failure(new FailedToStartServerException(Some(timeout))))
254+
Some(Failure(new FailedToStartServerTimeoutException(timeout)))
255255
else
256256
None
257257

modules/integration/src/test/scala/scala/cli/integration/BloopTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class BloopTests extends ScalaCliSuite {
6666
mergeErrIntoOut = true
6767
)
6868
expect(res.exitCode == 1)
69-
expect(res.out.text().contains("Server didn't start"))
69+
expect(res.out.text().contains("Server failed with exit code 1"))
7070
}
7171
}
7272

@@ -87,7 +87,7 @@ class BloopTests extends ScalaCliSuite {
8787
(root / "bloop.json").toString()
8888
).call(cwd = root, stderr = os.Pipe, check = false)
8989
expect(res.exitCode == 1)
90-
expect(res.err.text().contains("Server didn't start") || res.err.text().contains(
90+
expect(res.err.text().contains("Server failed with exit code 1") || res.err.text().contains(
9191
"java.lang.OutOfMemoryError: Garbage-collected heap size exceeded"
9292
))
9393
}

0 commit comments

Comments
 (0)