Skip to content

Commit

Permalink
use Aeson.eitherDecodeStrict and print json parsing errors (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhoy authored and paf31 committed Aug 11, 2017
1 parent c3ffdff commit bf69258
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ readPackageFile :: IO PackageConfig
readPackageFile = do
exists <- testfile packageFile
unless exists $ exitWithErr "psc-package.json does not exist. Maybe you need to run psc-package init?"
mpkg <- Aeson.decodeStrict . encodeUtf8 <$> readTextFile packageFile
mpkg <- Aeson.eitherDecodeStrict . encodeUtf8 <$> readTextFile packageFile
case mpkg of
Nothing -> exitWithErr "Unable to parse psc-package.json"
Just pkg -> return pkg
Left errors -> exitWithErr $ "Unable to parse psc-package.json: " <> T.pack errors
Right pkg -> return pkg

packageConfigToJSON :: PackageConfig -> Text
packageConfigToJSON =
Expand Down Expand Up @@ -145,10 +145,10 @@ readPackageSet PackageConfig{ set } = do
let dbFile = ".psc-package" </> fromText set </> ".set" </> "packages.json"
exists <- testfile dbFile
unless exists $ exitWithErr $ format (fp%" does not exist") dbFile
mdb <- Aeson.decodeStrict . encodeUtf8 <$> readTextFile dbFile
mdb <- Aeson.eitherDecodeStrict . encodeUtf8 <$> readTextFile dbFile
case mdb of
Nothing -> exitWithErr "Unable to parse packages.json"
Just db -> return db
Left errors -> exitWithErr $ "Unable to parse packages.json: " <> T.pack errors
Right db -> return db

writePackageSet :: PackageConfig -> PackageSet -> IO ()
writePackageSet PackageConfig{ set } =
Expand Down

0 comments on commit bf69258

Please sign in to comment.