Skip to content

Commit 14c73f1

Browse files
authored
Merge pull request #5548 from unisonweb/no-ExitSuccess-message
allow threads to die with ExitSuccess without printing a message
2 parents c1df635 + e4e5b8f commit 14c73f1

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

unison-cli/src/Unison/Main.hs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import ArgParse
2525
)
2626
import Compat (defaultInterruptHandler, withInterruptHandler)
2727
import Control.Concurrent (newEmptyMVar, runInUnboundThread, takeMVar)
28-
import Control.Exception (displayException, evaluate)
28+
import Control.Exception (displayException, evaluate, fromException)
2929
import Data.ByteString.Lazy qualified as BL
3030
import Data.Either.Validation (Validation (..))
3131
import Data.List.NonEmpty (NonEmpty)
@@ -45,6 +45,7 @@ import System.Directory
4545
removeDirectoryRecursive,
4646
)
4747
import System.Environment (getExecutablePath, getProgName, withArgs)
48+
import System.Exit (ExitCode (..))
4849
import System.Exit qualified as Exit
4950
import System.Exit qualified as System
5051
import System.FilePath
@@ -110,26 +111,30 @@ main version = do
110111
-- Replace the default exception handler with one complains loudly, because we shouldn't have any uncaught exceptions.
111112
-- Sometimes `show` and `displayException` are different strings; in this case, we want to show them both, so this
112113
-- issue is easier to debug.
114+
--
115+
-- We've made one exception for `ExitSuccess`, because we've discovered the `lsp` library unhelpfully throws it from a
116+
-- background thread as part of the default "exit notification handler", with no way to modify the behavior.
113117
setUncaughtExceptionHandler \exception -> do
114-
let shown = tShow exception
115-
let displayed = Text.pack (displayException exception)
116-
let indented = Text.unlines . map (" " <>) . Text.lines
118+
when (not (isExitSuccess exception)) do
119+
let shown = tShow exception
120+
let displayed = Text.pack (displayException exception)
121+
let indented = Text.unlines . map (" " <>) . Text.lines
117122

118-
Text.hPutStrLn stderr . Text.unlines . fold $
119-
[ [ "Uh oh, an unexpected exception brought the process down! That should never happen. Please file a bug report.",
120-
"",
121-
"Here's a stringy rendering of the exception:",
122-
"",
123-
indented shown
124-
],
125-
if shown /= displayed
126-
then
127-
[ "And here's a different one, in case it's easier to understand:",
128-
"",
129-
indented displayed
130-
]
131-
else []
132-
]
123+
Text.hPutStrLn stderr . Text.unlines . fold $
124+
[ [ "Uh oh, an unexpected exception brought the process down! That should never happen. Please file a bug report.",
125+
"",
126+
"Here's a stringy rendering of the exception:",
127+
"",
128+
indented shown
129+
],
130+
if shown /= displayed
131+
then
132+
[ "And here's a different one, in case it's easier to understand:",
133+
"",
134+
indented displayed
135+
]
136+
else []
137+
]
133138

134139
withCP65001 . runInUnboundThread . Ki.scoped $ \scope -> do
135140
interruptHandler <- defaultInterruptHandler
@@ -360,6 +365,10 @@ main version = do
360365
-- startNativeRuntime saves the path to `unison-runtime`
361366
=<< RTI.startNativeRuntime (Version.gitDescribeWithDate version) nrtp
362367

368+
isExitSuccess :: SomeException -> Bool
369+
isExitSuccess =
370+
(== Just ExitSuccess) . fromException
371+
363372
-- | Set user agent and configure TLS on global http client.
364373
-- Note that the authorized http client is distinct from the global http client.
365374
initHTTPClient :: Version -> IO ()

0 commit comments

Comments
 (0)