on master help sign in
Improve the error message if we can't find the file (#858)
8483aedNeil Mitchell
src/Development/IDE/State/FileStore.hs+9−8
@@ -25,6 +25,7 @@ import Development.IDE.UtilGHC
25import Control.Concurrent.Extra
25import Control.Concurrent.Extra
26import Control.Exception
26import Control.Exception
27import GHC.Generics
27import GHC.Generics
28+import System.IO.Error
28import qualified Data.ByteString.Char8 as BS
29import qualified Data.ByteString.Char8 as BS
29import Development.IDE.Types.Diagnostics
30import Development.IDE.Types.Diagnostics
30import Data.Time
31import Data.Time
@@ -86,15 +87,15 @@ showTimePrecise UTCTime{..} = show (toModifiedJulianDay utctDay, diffTimeToPicos
86getModificationTimeRule :: Var DirtyFiles -> Rules ()
87getModificationTimeRule :: Var DirtyFiles -> Rules ()
87getModificationTimeRule dirty =
88getModificationTimeRule dirty =
88 defineEarlyCutoff $ \GetModificationTime file -> do
89 defineEarlyCutoff $ \GetModificationTime file -> do
90+ let wrap time = (Just $ BS.pack $ showTimePrecise time, ([], Just time))
89 alwaysRerun
91 alwaysRerun
90− res <- liftIO $ ideTryIOException file $ do
91− mp <- readVar dirty
92+ mp <- liftIO $ readVar dirty
92− case Map.lookup file mp of
93+ case Map.lookup file mp of
93− Just (time, _) -> return time
94+ Just (time, _) -> return $ wrap time
94− Nothing -> Dir.getModificationTime file
95+ Nothing -> liftIO $ fmap wrap (Dir.getModificationTime file) `catch` \(e :: IOException) -> do
95− case res of
96+ let err | isDoesNotExistError e = "File does not exist: " ++ file
96− Left err -> return (Nothing, ([err], Nothing))
97+ | otherwise = "IO error while reading " ++ file ++ ", " ++ displayException e
97− Right time -> return (Just $ BS.pack $ showTimePrecise time, ([], Just time))
98+ return (Nothing, ([ideErrorText file $ T.pack err], Nothing))
98
99
99
100
100getFileContentsRule :: Var DirtyFiles -> Rules ()
101getFileContentsRule :: Var DirtyFiles -> Rules ()