From 5874ad920efb48deba8b57056d2f32550aca646d Mon Sep 17 00:00:00 2001 From: Devin Fisher Date: Fri, 5 Aug 2022 09:57:22 -0600 Subject: [PATCH 1/2] add output when book server socket fails to create --- main/src/main/scala/sbt/Main.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main/src/main/scala/sbt/Main.scala b/main/src/main/scala/sbt/Main.scala index 6bb147f7d..d8f5d2eb2 100644 --- a/main/src/main/scala/sbt/Main.scala +++ b/main/src/main/scala/sbt/Main.scala @@ -153,9 +153,13 @@ private[sbt] object xMain { if (ITerminal.get.withRawInput(System.in.read) == 'n'.toInt) Some(Exit(1)) else None (None, exit) - case _: ServerAlreadyBootingException => + case e: ServerAlreadyBootingException => if (SysProp.forceServerStart) (None, None) - else (None, Some(Exit(2))) + else { + println("Boot server failed to create socket") + e.printStackTrace() + (None, Some(Exit(2))) + } case _: UnsatisfiedLinkError => (None, None) } } From 9f9b08edbd49d1b48aa9e544999cfe225efac935 Mon Sep 17 00:00:00 2001 From: Devin Fisher Date: Mon, 8 Aug 2022 11:21:43 -0600 Subject: [PATCH 2/2] refactor printing error to an in-function function --- main/src/main/scala/sbt/Main.scala | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/main/src/main/scala/sbt/Main.scala b/main/src/main/scala/sbt/Main.scala index d8f5d2eb2..88babfe0b 100644 --- a/main/src/main/scala/sbt/Main.scala +++ b/main/src/main/scala/sbt/Main.scala @@ -141,13 +141,17 @@ private[sbt] object xMain { private def getSocketOrExit( configuration: xsbti.AppConfiguration - ): (Option[BootServerSocket], Option[Exit]) = - try (Some(new BootServerSocket(configuration)) -> None) + ): (Option[BootServerSocket], Option[Exit]) = { + 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 { case e: ServerAlreadyBootingException if System.console != null && !ITerminal.startedByRemoteClient => - println("sbt thinks that server is already booting because of this exception:") - e.printStackTrace() + printThrowable(e) println("Create a new server? y/n (default y)") val exit = if (ITerminal.get.withRawInput(System.in.read) == 'n'.toInt) Some(Exit(1)) @@ -156,12 +160,12 @@ private[sbt] object xMain { case e: ServerAlreadyBootingException => if (SysProp.forceServerStart) (None, None) else { - println("Boot server failed to create socket") - e.printStackTrace() + printThrowable(e) (None, Some(Exit(2))) } case _: UnsatisfiedLinkError => (None, None) } + } } final class ScriptMain extends xsbti.AppMain {