Skip to content

Commit 90f8255

Browse files
Re-throw asynchronous exceptions in makeThreadPool (#92)
Make running doctests interruptable
1 parent 73b4683 commit 90f8255

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/Test/DocTest/Internal/Runner.hs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ module Test.DocTest.Internal.Runner where
88
import Prelude hiding (putStr, putStrLn, error)
99

1010
import Control.Concurrent (Chan, writeChan, readChan, newChan, forkIO, ThreadId, myThreadId, MVar, newMVar)
11-
import Control.Exception (SomeException)
11+
import Control.Exception (SomeException, AsyncException, throw)
1212
import Control.Monad hiding (forM_)
13-
import Control.Monad.Catch (catch)
13+
import Control.Monad.Catch (catches, Handler (Handler))
1414
import Data.Foldable (forM_)
1515
import Data.Function (on)
1616
import Data.List (sortBy)
@@ -323,9 +323,16 @@ makeThreadPool nThreads parseArgs mutator = do
323323
forkIO $ withGhc parseArgs $ forever $ do
324324
modName <- liftIO $ readChan input
325325
threadId <- liftIO myThreadId
326-
catch
326+
let update e = liftIO $ writeChan output (threadId, UpdateInternalError modName e)
327+
catches
327328
(mutator output modName)
328-
(\e -> liftIO $ writeChan output (threadId, UpdateInternalError modName e))
329+
-- Re-throw AsyncException, otherwise execution will not terminate on
330+
-- SIGINT (ctrl-c). All AsyncExceptions are re-thrown (not just
331+
-- UserInterrupt) because all of them indicate severe conditions and
332+
-- should not occur during normal operation.
333+
[ Handler (\e -> throw (e :: AsyncException))
334+
, Handler (\e -> update (e :: SomeException))
335+
]
329336
return (input, output)
330337

331338
reportModuleParsed :: (?verbosity::LogLevel, ?threadId::ThreadId) => ModuleName -> Int -> Report ()

0 commit comments

Comments
 (0)