Skip to content

Commit

Permalink
blooprifle: report exit code in exception
Browse files Browse the repository at this point in the history
To help debugging, the failure code is now part of the exception in
case the bloop server failed to start.
  • Loading branch information
Flowdalic committed Feb 9, 2023
1 parent f64512a commit 50620c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Expand Up @@ -2,5 +2,11 @@ package scala.build.blooprifle

import scala.concurrent.duration.Duration

final class FailedToStartServerException(timeoutOpt: Option[Duration] = None)
extends Exception("Server didn't start" + timeoutOpt.fold("")(t => s" after $t"))
abstract class FailedToStartServerException(message: String)
extends Exception(message)

final class FailedToStartServerExitCodeException(exitCode: Int)
extends FailedToStartServerException(f"Server failed with code $exitCode")

final class FailedToStartServerTimeoutException(timeout: Duration)
extends FailedToStartServerException(f"Server didn't start after $timeout")
Expand Up @@ -13,7 +13,7 @@ import java.nio.file.{Files, Path, Paths}
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.{ExecutorService, ScheduledExecutorService, ScheduledFuture}

import scala.build.blooprifle.{BloopRifleConfig, BloopRifleLogger, BspConnection, BspConnectionAddress, FailedToStartServerException}
import scala.build.blooprifle.{BloopRifleConfig, BloopRifleLogger, BspConnection, BspConnectionAddress, FailedToStartServerExitCodeException, FailedToStartServerTimeoutException}
import scala.concurrent.duration._
import scala.concurrent.{Await, Future, Promise}
import scala.util.control.NonFatal
Expand Down Expand Up @@ -247,11 +247,11 @@ object Operations {
}
val completionOpt =
if (!p.isAlive() && exitCode != serverAlreadyRunningExitCode)
Some(Failure(new FailedToStartServerException))
Some(Failure(new FailedToStartServerExitCodeException(exitCode)))
else if (check(address, logger))
Some(Success(()))
else if (timeout.isFinite && System.currentTimeMillis() - start > timeout.toMillis)
Some(Failure(new FailedToStartServerException(Some(timeout))))
Some(Failure(new FailedToStartServerTimeoutException(timeout)))
else
None

Expand Down

0 comments on commit 50620c7

Please sign in to comment.