[Git][ghc/ghc][wip/T15616] base: Better error message on invalid getSystemTimerManager call

Ben Gamari gitlab at gitlab.haskell.org
Wed Jun 24 18:55:45 UTC 2020



Ben Gamari pushed to branch wip/T15616 at Glasgow Haskell Compiler / GHC


Commits:
353e1230 by Ben Gamari at 2020-06-24T14:55:37-04:00
base: Better error message on invalid getSystemTimerManager call

Previously we would produce a rather unhelpful pattern match failure
error in the case where the user called `getSystemTimerManager` in a
program which isn't built with `-threaded`. This understandably confused
the user in #15616.

Fixes #15616.

- - - - -


1 changed file:

- libraries/base/GHC/Event/Thread.hs


Changes:

=====================================
libraries/base/GHC/Event/Thread.hs
=====================================
@@ -19,6 +19,7 @@ module GHC.Event.Thread
 import Control.Exception (finally, SomeException, toException)
 import Data.Foldable (forM_, mapM_, sequence_)
 import Data.IORef (IORef, newIORef, readIORef, writeIORef)
+import Data.Maybe (fromMaybe)
 import Data.Tuple (snd)
 import Foreign.C.Error (eBADF, errnoToIOError)
 import Foreign.C.Types (CInt(..), CUInt(..))
@@ -213,8 +214,9 @@ ioManagerLock = unsafePerformIO $ do
 
 getSystemTimerManager :: IO TM.TimerManager
 getSystemTimerManager = do
-  Just mgr <- readIORef timerManager
-  return mgr
+  fromMaybe err `fmap` readIORef timerManager
+  where
+    err = error "GHC.Event.Thread.getSystemTimerManager: the TimerManager requires linking against the threaded runtime"
 
 foreign import ccall unsafe "getOrSetSystemTimerThreadEventManagerStore"
     getOrSetSystemTimerThreadEventManagerStore :: Ptr a -> IO (Ptr a)



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/353e1230538a9adeca25930d57190a6df88a4cdc

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/353e1230538a9adeca25930d57190a6df88a4cdc
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200624/5d78a15b/attachment.html>


More information about the ghc-commits mailing list