FIX nasty error caused by exception when looking at sockets

This commit is contained in:
Nathan Dwarshuis 2022-07-08 02:11:42 -04:00
parent cdba344695
commit 936a3b16b8
2 changed files with 6 additions and 8 deletions

View File

@ -128,8 +128,7 @@ runEditor = sometimesIO_ "text editor" "emacs" tree cmd
where
cmd = spawnCmd myEditor
["-c", "-e", doubleQuote "(select-frame-set-input-focus (selected-frame))"]
tree = toAnd_ (sysExe myEditor) (socketExists "emacs" socketName)
socketName = (</> "emacs" </> "server") <$> getEnv "XDG_RUNTIME_DIR"
tree = Only_ $ sysExe myEditor
runFileManager :: SometimesX
runFileManager = sometimesExe "file browser" "pcmanfm" True "pcmanfm"

View File

@ -119,6 +119,7 @@ import Data.Maybe
import Data.Yaml
import GHC.Generics (Generic)
import GHC.IO.Exception (ioe_description)
import DBus hiding (typeOf)
import DBus.Client
@ -780,12 +781,10 @@ socketExists n = IOTest_ ("test if " ++ n ++ " socket exists") . socketExists'
socketExists' :: IO FilePath -> IO (Maybe Msg)
socketExists' getPath = do
p <- getPath
e <- fileExist p
s <- isSocket <$> getFileStatus p
return $ case (e, s) of
(True, True) -> Nothing
(False, _) -> toErr $ "could not find socket at " ++ p
(_, False) -> toErr $ p ++ " is not a socket"
r <- tryIOError $ getFileStatus p
return $ case r of
Left e -> toErr $ ioe_description e
Right s -> if isSocket s then Nothing else toErr $ p ++ " is not a socket"
where
toErr = Just . Msg Error