Skip to content

Commit

Permalink
Improve logging on broken symlinks wrt #880
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Sep 3, 2023
1 parent 50252d8 commit 4b7d165
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/GHCup/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ cabalSet = do
handleIO' NoSuchThing (\_ -> pure Nothing) $ do
broken <- liftIO $ isBrokenSymlink cabalbin
if broken
then pure Nothing
then do
logWarn $ "Broken symlink at " <> T.pack cabalbin
pure Nothing
else do
link <- liftIO
$ handleIO' InvalidArgument
Expand Down Expand Up @@ -466,7 +468,9 @@ stackSet = do
handleIO' NoSuchThing (\_ -> pure Nothing) $ do
broken <- liftIO $ isBrokenSymlink stackBin
if broken
then pure Nothing
then do
logWarn $ "Broken symlink at " <> T.pack stackBin
pure Nothing
else do
link <- liftIO
$ handleIO' InvalidArgument
Expand Down Expand Up @@ -520,15 +524,17 @@ isLegacyHLS ver = do


-- Return the currently set hls version, if any.
hlsSet :: (MonadReader env m, HasDirs env, MonadIO m, MonadThrow m, MonadCatch m) => m (Maybe Version)
hlsSet :: (HasLog env, MonadReader env m, HasDirs env, MonadIO m, MonadThrow m, MonadCatch m) => m (Maybe Version)
hlsSet = do
Dirs {..} <- getDirs
let hlsBin = binDir </> "haskell-language-server-wrapper" <> exeExt

liftIO $ handleIO' NoSuchThing (\_ -> pure Nothing) $ do
broken <- isBrokenSymlink hlsBin
handleIO' NoSuchThing (\_ -> pure Nothing) $ do
broken <- liftIO $ isBrokenSymlink hlsBin
if broken
then pure Nothing
then do
logWarn $ "Broken symlink at " <> T.pack hlsBin
pure Nothing
else do
link <- liftIO $ getLinkTarget hlsBin
Just <$> linkVersion link
Expand Down Expand Up @@ -556,6 +562,7 @@ hlsSet = do
-- | Return the GHC versions the currently selected HLS supports.
hlsGHCVersions :: ( MonadReader env m
, HasDirs env
, HasLog env
, MonadIO m
, MonadThrow m
, MonadCatch m
Expand Down

0 comments on commit 4b7d165

Please sign in to comment.