From 0d37a9eae24a18b02b1bd38c0d854656026e6c04 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 4d30a9920..1dcde1001 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 157030212ac331fbe9fbd8f295c444328fc39c5d 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 1dcde1001..c2cbb74f9 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 {