Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blooprifle: report exit code in exception #1844

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 exit 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
Expand Up @@ -66,7 +66,7 @@ class BloopTests extends ScalaCliSuite {
mergeErrIntoOut = true
)
expect(res.exitCode == 1)
expect(res.out.text().contains("Server didn't start"))
expect(res.out.text().contains("Server failed with exit code 1"))
}
}

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