refactor printing error to an in-function function

This commit is contained in:
Devin Fisher 2022-08-08 11:21:43 -06:00 committed by Eugene Yokota
parent 5874ad920e
commit 9f9b08edbd
1 changed files with 10 additions and 6 deletions

View File

@ -141,13 +141,17 @@ private[sbt] object xMain {
private def getSocketOrExit( private def getSocketOrExit(
configuration: xsbti.AppConfiguration configuration: xsbti.AppConfiguration
): (Option[BootServerSocket], Option[Exit]) = ): (Option[BootServerSocket], Option[Exit]) = {
try (Some(new BootServerSocket(configuration)) -> None) def printThrowable(e: Throwable): Unit = {
println("sbt thinks that server is already booting because of this exception:")
e.printStackTrace()
}
try Some(new BootServerSocket(configuration)) -> None
catch { catch {
case e: ServerAlreadyBootingException case e: ServerAlreadyBootingException
if System.console != null && !ITerminal.startedByRemoteClient => if System.console != null && !ITerminal.startedByRemoteClient =>
println("sbt thinks that server is already booting because of this exception:") printThrowable(e)
e.printStackTrace()
println("Create a new server? y/n (default y)") println("Create a new server? y/n (default y)")
val exit = val exit =
if (ITerminal.get.withRawInput(System.in.read) == 'n'.toInt) Some(Exit(1)) if (ITerminal.get.withRawInput(System.in.read) == 'n'.toInt) Some(Exit(1))
@ -156,12 +160,12 @@ private[sbt] object xMain {
case e: ServerAlreadyBootingException => case e: ServerAlreadyBootingException =>
if (SysProp.forceServerStart) (None, None) if (SysProp.forceServerStart) (None, None)
else { else {
println("Boot server failed to create socket") printThrowable(e)
e.printStackTrace()
(None, Some(Exit(2))) (None, Some(Exit(2)))
} }
case _: UnsatisfiedLinkError => (None, None) case _: UnsatisfiedLinkError => (None, None)
} }
}
} }
final class ScriptMain extends xsbti.AppMain { final class ScriptMain extends xsbti.AppMain {