@@ -69,7 +69,7 @@ import Development.IDE.Types.Location
69
69
import Development.IDE.Types.Options
70
70
import Control.Concurrent.Async
71
71
import Control.Concurrent.Extra
72
- import Control.Exception
72
+ import Control.Exception.Extra
73
73
import Control.DeepSeq
74
74
import System.Time.Extra
75
75
import Data.Typeable
@@ -126,14 +126,19 @@ addIdeGlobal x = do
126
126
addIdeGlobalExtras :: IsIdeGlobal a => ShakeExtras -> a -> IO ()
127
127
addIdeGlobalExtras ShakeExtras {globals} x@ (typeOf -> ty) =
128
128
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
130
130
Nothing -> return $! HMap. insert ty (toDyn x) mp
131
131
132
132
133
133
getIdeGlobalExtras :: forall a . IsIdeGlobal a => ShakeExtras -> IO a
134
134
getIdeGlobalExtras 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
137
142
138
143
getIdeGlobalAction :: forall a . IsIdeGlobal a => Action a
139
144
getIdeGlobalAction = liftIO . getIdeGlobalExtras =<< getShakeExtras
0 commit comments