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

Add support for absolute paths in Bloopgun error handling #2132

Merged
merged 4 commits into from
Sep 26, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions bloopgun/src/main/scala/bloop/bloopgun/Bloopgun.scala
Original file line number Diff line number Diff line change
Expand Up @@ -503,17 +503,24 @@ class BloopgunCli(
(exitServerStatus, usedExtraJvmOpts)
} catch {
case e: IOException =>
val javaBinaryName = if (Environment.isWindows) {
"java.exe"
} else {
"java"
}
val javaExec = sys.env
.get("JAVA_HOME")
.orElse(sys.props.get("java.home"))
.map(Paths.get(_).resolve("bin/java"))
.map(Paths.get(_).resolve(s"bin/${javaBinaryName}"))
.filter(_.toFile().isFile())
.map(_.toString())
val javaErrorMessage = "Cannot run program \"java\""
val javaErrorMessage = "Cannot run program \".*java\"".r
val errorCode = "error=2"
javaExec match {
case Some(java)
if e.getMessage().contains(javaErrorMessage) && e.getMessage.contains(errorCode) =>
if javaErrorMessage.pattern.matcher(e.getMessage()).find() && e.getMessage.contains(
errorCode
) =>
logger.info(s"Java executable was not available on PATH, retrying with $java")
val (cmd, usedExtraJvmOpts) =
cmdWithArgs(found, extraJvmOpts, List(java), globalSettings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,11 @@ object GlobalSettingsSpec extends LauncherBaseSuite(BuildInfo.version, BuildInfo
}
}

test("fail to start server when bloop.json Java home is invalid") {
test("should start server even when bloop.json Java home is invalid") {
// Create bloop.json with Java home pointing to non-existent path.
val doesnotexist = "does-not-exist"
runBspLauncherWithGlobalJsonSettings(s"""{"javaHome": "$doesnotexist"}""") { result =>
assert(result.status == Some(LauncherStatus.FailedToConnectToServer))
assertLogsContain(
List(doesnotexist, "Error when starting server"),
result.launcherLogs
)
assert(result.status == Some(LauncherStatus.SuccessfulRun))
}
}

Expand Down
Loading