Handle failures properly

Attoparsec error are discarded since they are basically useless.
This commit is contained in:
rnhmjoj 2015-07-07 20:59:53 +02:00
parent 75d640063f
commit 20ef16e3f2
2 changed files with 12 additions and 8 deletions

View File

@ -32,15 +32,19 @@ fuzzy x = filter (any (isInfixOf x) . strings)
-- Keychain access --
keychainList :: IO [FilePath]
keychainList =
runParser parseKeychainList <$>
readProcess "security" ["list-keychains"] ""
keychainList = do
raw <- readProcess "security" ["list-keychains"] ""
case runParser parseKeychainList raw of
Just list -> return list
Nothing -> error "failed to parse active keychains list"
getKeychain :: IO Keychain
getKeychain = do
paths <- filter ((/="System") . takeBaseName) <$> keychainList
dump <- readProcess "security" ("dump-keychain" : "-d" : paths) ""
return (runParser parseKeychain dump)
raw <- readProcess "security" ("dump-keychain" : "-d" : paths) ""
case runParser parseKeychain raw of
Just items -> return items
Nothing -> error "failed to parse keychain"
sendClipboard :: String -> IO ()
sendClipboard text =

View File

@ -14,11 +14,11 @@ import Data.Hex (unhex)
import Data.Time
runParser :: Monoid a => Parser a -> String -> a
runParser :: Parser a -> String -> Maybe a
runParser parser = handle . parseOnly parser . pack
where
handle (Left _) = mempty
handle (Right x) = x
handle (Left _) = Nothing
handle (Right x) = Just x
-- Parsers --