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 --
|
-- Keychain access --
|
||||||
|
|
||||||
keychainList :: IO [FilePath]
|
keychainList :: IO [FilePath]
|
||||||
keychainList =
|
keychainList = do
|
||||||
runParser parseKeychainList <$>
|
raw <- readProcess "security" ["list-keychains"] ""
|
||||||
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 :: IO Keychain
|
||||||
getKeychain = do
|
getKeychain = do
|
||||||
paths <- filter ((/="System") . takeBaseName) <$> keychainList
|
paths <- filter ((/="System") . takeBaseName) <$> keychainList
|
||||||
dump <- readProcess "security" ("dump-keychain" : "-d" : paths) ""
|
raw <- readProcess "security" ("dump-keychain" : "-d" : paths) ""
|
||||||
return (runParser parseKeychain dump)
|
case runParser parseKeychain raw of
|
||||||
|
Just items -> return items
|
||||||
|
Nothing -> error "failed to parse keychain"
|
||||||
|
|
||||||
sendClipboard :: String -> IO ()
|
sendClipboard :: String -> IO ()
|
||||||
sendClipboard text =
|
sendClipboard text =
|
||||||
|
@ -14,11 +14,11 @@ import Data.Hex (unhex)
|
|||||||
import Data.Time
|
import Data.Time
|
||||||
|
|
||||||
|
|
||||||
runParser :: Monoid a => Parser a -> String -> a
|
runParser :: Parser a -> String -> Maybe a
|
||||||
runParser parser = handle . parseOnly parser . pack
|
runParser parser = handle . parseOnly parser . pack
|
||||||
where
|
where
|
||||||
handle (Left _) = mempty
|
handle (Left _) = Nothing
|
||||||
handle (Right x) = x
|
handle (Right x) = Just x
|
||||||
|
|
||||||
|
|
||||||
-- Parsers --
|
-- Parsers --
|
||||||
|
Loading…
Reference in New Issue
Block a user