@@ -29,7 +29,7 @@ module Unison.Runtime.Interface
29
29
where
30
30
31
31
import Control.Concurrent.STM as STM
32
- import Control.Exception (throwIO )
32
+ import Control.Exception (fromException , throwIO , tryJust )
33
33
import Control.Monad
34
34
import Control.Monad.State
35
35
import Data.Binary.Get (runGetOrFail )
@@ -1042,11 +1042,24 @@ evalInContext ppe ctx activeThreads w = do
1042
1042
decom = decompileCtx crs ctx
1043
1043
finish = fmap (first listErrors . decom)
1044
1044
1045
- prettyError (PE _ p) = p
1046
- prettyError (BU tr0 nm c) =
1047
- bugMsg ppe tr nm $ decom c
1045
+ prettyError e
1046
+ | Just rte <- fromException e = case rte of
1047
+ PE _ p -> Just p
1048
+ BU tr0 nm c -> Just . bugMsg ppe tr nm $ decom c
1049
+ where
1050
+ tr = first (backmapRef ctx) <$> tr0
1051
+ | Just (Panic msg mval) <- fromException e =
1052
+ Just . P. callout panicIcon . P. linesNonEmpty $
1053
+ [ P. wrap $
1054
+ " The program halted with a runtime panic:" ,
1055
+ " " ,
1056
+ P. string msg
1057
+ ]
1058
+ ++ maybe [] (render . decom) mval
1059
+ | otherwise = Nothing
1048
1060
where
1049
- tr = first (backmapRef ctx) <$> tr0
1061
+ render (errs, tm) =
1062
+ [" " , P. indentN 2 $ pretty ppe tm, tabulateErrors errs]
1050
1063
1051
1064
debugText fancy val = case decom val of
1052
1065
(errs, dv)
@@ -1060,8 +1073,7 @@ evalInContext ppe ctx activeThreads w = do
1060
1073
1061
1074
result <-
1062
1075
traverse (const $ readIORef r)
1063
- . first prettyError
1064
- <=< try
1076
+ <=< tryJust prettyError
1065
1077
$ apply0 (Just hook) ((ccache ctx) {tracer = debugText}) activeThreads w
1066
1078
pure $ finish result
1067
1079
@@ -1183,6 +1195,9 @@ stackTrace ppe tr = "\nStack trace:\n" <> P.indentN 2 (P.lines $ f <$> tr)
1183
1195
icon :: Pretty ColorText
1184
1196
icon = " 💔💥"
1185
1197
1198
+ panicIcon :: Pretty ColorText
1199
+ panicIcon = " 💥🤯💥"
1200
+
1186
1201
catchInternalErrors ::
1187
1202
IO (Either Error a ) ->
1188
1203
IO (Either Error a )
0 commit comments