on master help sign in
Improve the error message if we can't find the file (#858)
commit8483aed07cf73cc1090f1cf3353cc22d7cfd0c8d authorNeil Mitchell <35463327+neil-da@users.noreply.github.com> dateThu 2 May 2019, 20:16 (7 years ago) parent828f3af
1 file changed+9−8
src/Development/IDE/State/FileStore.hs+9−8
src/Development/IDE/State/FileStore.hs+9−8
@@ -25,6 +25,7 @@ import Development.IDE.UtilGHC
2525import Control.Concurrent.Extra
2626import Control.Exception
2727import GHC.Generics
28+import System.IO.Error
2829import qualified Data.ByteString.Char8 as BS
2930import Development.IDE.Types.Diagnostics
3031import Data.Time
@@ -86,15 +87,15 @@ showTimePrecise UTCTime{..} = show (toModifiedJulianDay utctDay, diffTimeToPicos
8687getModificationTimeRule :: Var DirtyFiles -> Rules ()
8788getModificationTimeRule dirty =
8889 defineEarlyCutoff $ \GetModificationTime file -> do
90+ let wrap time = (Just $ BS.pack $ showTimePrecise time, ([], Just time))
8991 alwaysRerun
90− res <- liftIO $ ideTryIOException file $ do
91− mp <- readVar dirty
92− case Map.lookup file mp of
93− Just (time, _) -> return time
94− Nothing -> Dir.getModificationTime file
95− case res of
96− Left err -> return (Nothing, ([err], Nothing))
97− Right time -> return (Just $ BS.pack $ showTimePrecise time, ([], Just time))
92+ mp <- liftIO $ readVar dirty
93+ case Map.lookup file mp of
94+ Just (time, _) -> return $ wrap time
95+ Nothing -> liftIO $ fmap wrap (Dir.getModificationTime file) `catch` \(e :: IOException) -> do
96+ let err | isDoesNotExistError e = "File does not exist: " ++ file
97+ | otherwise = "IO error while reading " ++ file ++ ", " ++ displayException e
98+ return (Nothing, ([ideErrorText file $ T.pack err], Nothing))
9899
99100
100101getFileContentsRule :: Var DirtyFiles -> Rules ()