Skip to content

Commit e8eb9e5

Browse files
Devin Fishereed3si9n
Devin Fisher
authored andcommitted
refactor printing error to an in-function function
1 parent 2a0a33d commit e8eb9e5

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

main/src/main/scala/sbt/Main.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,17 @@ private[sbt] object xMain {
141141

142142
private def getSocketOrExit(
143143
configuration: xsbti.AppConfiguration
144-
): (Option[BootServerSocket], Option[Exit]) =
145-
try (Some(new BootServerSocket(configuration)) -> None)
144+
): (Option[BootServerSocket], Option[Exit]) = {
145+
def printThrowable(e: Throwable): Unit = {
146+
println("sbt thinks that server is already booting because of this exception:")
147+
e.printStackTrace()
148+
}
149+
150+
try Some(new BootServerSocket(configuration)) -> None
146151
catch {
147152
case e: ServerAlreadyBootingException
148153
if System.console != null && !ITerminal.startedByRemoteClient =>
149-
println("sbt thinks that server is already booting because of this exception:")
150-
e.printStackTrace()
154+
printThrowable(e)
151155
println("Create a new server? y/n (default y)")
152156
val exit =
153157
if (ITerminal.get.withRawInput(System.in.read) == 'n'.toInt) Some(Exit(1))
@@ -156,12 +160,12 @@ private[sbt] object xMain {
156160
case e: ServerAlreadyBootingException =>
157161
if (SysProp.forceServerStart) (None, None)
158162
else {
159-
println("Boot server failed to create socket")
160-
e.printStackTrace()
163+
printThrowable(e)
161164
(None, Some(Exit(2)))
162165
}
163166
case _: UnsatisfiedLinkError => (None, None)
164167
}
168+
}
165169
}
166170

167171
final class ScriptMain extends xsbti.AppMain {

0 commit comments

Comments
 (0)