Skip to content

Commit 0097132

Browse files
committed
Improve FinderCache error messages and backtraces
1 parent decf07e commit 0097132

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

ghcide/src/Development/IDE/Types/HscEnvEq.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Control.Concurrent.Async (Async, async, waitCatch)
1212
import Control.Concurrent.Strict (modifyVar, newVar)
1313
import Control.DeepSeq (force, rwhnf)
1414
import Control.Exception (evaluate, mask, throwIO)
15+
import qualified Control.Exception as Exc
1516
import Control.Monad.Extra (eitherM, join, mapMaybeM)
1617
import Data.Either (fromRight)
1718
import Data.IORef
@@ -56,24 +57,24 @@ newHscEnvEq hscEnv' = do
5657
#if MIN_VERSION_ghc(9,11,0)
5758
let hscEnv = hscEnv'
5859
{ hsc_FC = FinderCache
59-
{ flushFinderCaches = \_ -> error "GHC should never call flushFinderCaches outside the driver"
60+
{ flushFinderCaches = \_ -> throwIO $ Exc.ErrorCall "flushFinderCaches: GHC should never call flushFinderCaches outside the driver"
6061
#if MIN_VERSION_ghc(9,13,0)
6162
, addToFinderCache = \im val -> do
6263
#else
6364
, addToFinderCache = \(GWIB im _) val -> do
6465
#endif
6566
if moduleUnit im `elem` hsc_all_home_unit_ids hscEnv'
66-
then error "tried to add home module to FC"
67+
then throwIO $ Exc.ErrorCall "addToFinderCache: tried to add home module to FC"
6768
else atomicModifyIORef' mod_cache $ \c -> (extendInstalledModuleEnv c im val, ())
6869
#if MIN_VERSION_ghc(9,13,0)
6970
, lookupFinderCache = \im -> do
7071
#else
7172
, lookupFinderCache = \(GWIB im _) -> do
7273
#endif
7374
if moduleUnit im `elem` hsc_all_home_unit_ids hscEnv'
74-
then error ("tried to lookup home module from FC" ++ showSDocUnsafe (ppr (im, hsc_all_home_unit_ids hscEnv')))
75+
then throwIO $ Exc.ErrorCall ("lookupFinderCache: tried to lookup home module from FC: " ++ showSDocUnsafe (ppr (im, hsc_all_home_unit_ids hscEnv')))
7576
else lookupInstalledModuleEnv <$> readIORef mod_cache <*> pure im
76-
, lookupFileCache = \fp -> error ("not used by HLS" ++ fp)
77+
, lookupFileCache = \fp -> throwIO $ Exc.ErrorCall ("lookupFileCache: Called without using setFileCacheHook for target: " ++ fp)
7778
}
7879
}
7980

0 commit comments

Comments
 (0)