sanitize control characters in main thread fatal exceptions
Sponsored-by: Noam Kremen on Patreon
This commit is contained in:
parent
11790df3e6
commit
fdac66ae10
3 changed files with 22 additions and 1 deletions
12
Messages.hs
12
Messages.hs
|
@ -48,12 +48,14 @@ module Messages (
|
|||
MessageState,
|
||||
prompt,
|
||||
mkPrompter,
|
||||
sanitizeTopLevelExceptionMessages,
|
||||
) where
|
||||
|
||||
import Control.Concurrent
|
||||
import Control.Monad.IO.Class
|
||||
import qualified Data.ByteString as S
|
||||
import qualified Data.ByteString.Char8 as S8
|
||||
import System.Exit
|
||||
|
||||
import Common
|
||||
import Types
|
||||
|
@ -323,3 +325,13 @@ mkPrompter = getConcurrency >>= \case
|
|||
(takeMVar l)
|
||||
(\v -> putMVar l v >> cleanup)
|
||||
(const $ run a)
|
||||
|
||||
{- Catch all (non-async) exceptions and display, santizing any control
|
||||
- characters in the exceptions. Exits nonzero on exception, so should only
|
||||
- be used at topmost level. -}
|
||||
sanitizeTopLevelExceptionMessages :: IO a -> IO a
|
||||
sanitizeTopLevelExceptionMessages a = catchNonAsync a go
|
||||
where
|
||||
go e = do
|
||||
warningIO (show e)
|
||||
exitWith $ ExitFailure 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue