Skip to content

Commit 3c6c547

Browse files
authored
Improve the error messages around IdeGlobal's (#598)
1 parent 95faeeb commit 3c6c547

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/Development/IDE/Core/Shake.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import Development.IDE.Types.Location
6969
import Development.IDE.Types.Options
7070
import Control.Concurrent.Async
7171
import Control.Concurrent.Extra
72-
import Control.Exception
72+
import Control.Exception.Extra
7373
import Control.DeepSeq
7474
import System.Time.Extra
7575
import Data.Typeable
@@ -126,14 +126,19 @@ addIdeGlobal x = do
126126
addIdeGlobalExtras :: IsIdeGlobal a => ShakeExtras -> a -> IO ()
127127
addIdeGlobalExtras 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

133133
getIdeGlobalExtras :: forall a . IsIdeGlobal a => ShakeExtras -> IO a
134134
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
137142

138143
getIdeGlobalAction :: forall a . IsIdeGlobal a => Action a
139144
getIdeGlobalAction = liftIO . getIdeGlobalExtras =<< getShakeExtras

0 commit comments

Comments
 (0)