Skip to content

Commit 7b06ef0

Browse files
committed
[cli] Improve wallet acquisition errors
1 parent c15902d commit 7b06ef0

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

cli/src/Core/Types/Mnemonics/Options.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Core.Types.Mnemonics.Options
44
, walletFileOption
55
) where
66

7+
import Control.Exception (try)
78
import Core.Encryption (decryptText)
89
import Core.Types.Mnemonics (Mnemonics (..), MnemonicsPhase (..))
910
import Data.Aeson
@@ -92,11 +93,15 @@ coreMnemonicsParser =
9293
id
9394
(decryptText <$> walletPassphraseCommon <*> mnemonicsEncryptedOption)
9495

96+
readJSONFile :: FilePath -> IO (Either String Object)
97+
readJSONFile fp = do
98+
econtent <- try $ BL.readFile fp
99+
case econtent of
100+
Left (e :: IOError) -> return $ Left $ show e
101+
Right content -> return $ Aeson.eitherDecode content
102+
95103
mnemonicsObject :: Parser Object
96-
mnemonicsObject =
97-
checkMapIO
98-
(fmap Aeson.eitherDecode . BL.readFile)
99-
walletFileOption
104+
mnemonicsObject = checkMapIO readJSONFile walletFileOption
100105

101106
mnemonicsParser :: Parser (Mnemonics 'DecryptedS)
102107
mnemonicsParser = withConfig (Just <$> mnemonicsObject) coreMnemonicsParser

0 commit comments

Comments
 (0)