Skip to content

Commit

Permalink
Merge pull request #2132 from andrzejressel/java_error_handing_on_win…
Browse files Browse the repository at this point in the history
…dows

Add support for absolute paths in Bloopgun error handling
  • Loading branch information
tgodzik authored Sep 26, 2023
2 parents c6abfe0 + fbde14b commit daae034
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
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

0 comments on commit daae034

Please sign in to comment.