Handle failures properly
Attoparsec error are discarded since they are basically useless.
This commit is contained in:
parent
75d640063f
commit
20ef16e3f2
14
src/Main.hs
14
src/Main.hs
@ -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 =
|
||||
|
@ -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 --
|
||||
|
Loading…
Reference in New Issue
Block a user