@@ -69,7 +69,7 @@ import Development.IDE.Types.Location
6969import Development.IDE.Types.Options
7070import Control.Concurrent.Async
7171import Control.Concurrent.Extra
72−import Control.Exception
72+import Control.Exception.Extra
7373import Control.DeepSeq
7474import System.Time.Extra
7575import Data.Typeable
@@ -126,14 +126,19 @@ addIdeGlobal x = do
126126addIdeGlobalExtras :: IsIdeGlobal a => ShakeExtras -> a -> IO ()
127127addIdeGlobalExtras ShakeExtras{globals} x@(typeOf -> ty) =
128128 liftIO $ modifyVar_ globals $ \mp -> case HMap.lookup ty mp of
129− Just _ -> error $ "Can't addIdeGlobal twice on the same type, got " ++ show ty
129+ Just _ -> errorIO $ "Internal error, addIdeGlobalExtras, got the same type twice for " ++ show ty
130130 Nothing -> return $! HMap.insert ty (toDyn x) mp
131131
132132
133133getIdeGlobalExtras :: forall a . IsIdeGlobal a => ShakeExtras -> IO a
134134getIdeGlobalExtras ShakeExtras{globals} = do
135− Just x <- HMap.lookup (typeRep (Proxy :: Proxy a)) <$> readVar globals
136− return $ fromDyn x $ error "Serious error, corrupt globals"
135+ let typ = typeRep (Proxy :: Proxy a)
136+ x <- HMap.lookup (typeRep (Proxy :: Proxy a)) <$> readVar globals
137+ case x of
138+ Just x
139+ | Just x <- fromDynamic x -> pure x
140+ | otherwise -> errorIO $ "Internal error, getIdeGlobalExtras, wrong type for " ++ show typ ++ " (got " ++ show (dynTypeRep x) ++ ")"
141+ Nothing -> errorIO $ "Internal error, getIdeGlobalExtras, no entry for " ++ show typ
137142
138143getIdeGlobalAction :: forall a . IsIdeGlobal a => Action a
139144getIdeGlobalAction = liftIO . getIdeGlobalExtras =<< getShakeExtras