Skip to content

Commit bf69258

Browse files
mjhoypaf31
authored andcommitted
use Aeson.eitherDecodeStrict and print json parsing errors (#58)
1 parent c3ffdff commit bf69258

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

app/Main.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ readPackageFile :: IO PackageConfig
6262
readPackageFile = do
6363
exists <- testfile packageFile
6464
unless exists $ exitWithErr "psc-package.json does not exist. Maybe you need to run psc-package init?"
65-
mpkg <- Aeson.decodeStrict . encodeUtf8 <$> readTextFile packageFile
65+
mpkg <- Aeson.eitherDecodeStrict . encodeUtf8 <$> readTextFile packageFile
6666
case mpkg of
67-
Nothing -> exitWithErr "Unable to parse psc-package.json"
68-
Just pkg -> return pkg
67+
Left errors -> exitWithErr $ "Unable to parse psc-package.json: " <> T.pack errors
68+
Right pkg -> return pkg
6969

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

153153
writePackageSet :: PackageConfig -> PackageSet -> IO ()
154154
writePackageSet PackageConfig{ set } =

0 commit comments

Comments
 (0)