Skip to content

Commit

Permalink
Prefer fail over error in IO computation
Browse files Browse the repository at this point in the history
TODO: Define custom Exception type
  • Loading branch information
Herbert Valerio Riedel committed Sep 22, 2016
1 parent aab83fa commit 568b4d7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/SimpleS3.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,19 @@ s3ListObjects1 (s3cfg@S3Cfg {..}) c pfx marker recurse = do
lbresult <-
case filterContent (s3qname "ListBucketResult") $ X.parseXML tmp of
[x] -> return x
res -> error $ "filterContent ListBucketResult failure: " ++ show res
res -> fail $ "filterContent ListBucketResult failure: " ++ show res

let conts_ = X.findChildren (s3qname "Contents") lbresult

conts <- forM conts_ $ \c ->
case parseXML c :: Maybe ObjMetaInfo of
Nothing -> error $ "parseXML ObjMetaInfo failed: " ++ X.showElement c
conts <- forM conts_ $ \cont ->
case parseXML cont :: Maybe ObjMetaInfo of
Nothing -> fail $ "parseXML ObjMetaInfo failed: " ++ X.showElement cont
Just x -> return x

let !isTrunc = case s3xmlGetStr lbresult "IsTruncated" of
Just "true" -> True
Just "false" -> False
_ -> error "s3ListObjects1: invalid or missing IsTruncated field"
isTrunc <- case s3xmlGetStr lbresult "IsTruncated" of
Just "true" -> pure True
Just "false" -> pure False
_ -> fail "invalid or missing IsTruncated field"

return (isTrunc,conts)
where
Expand Down

0 comments on commit 568b4d7

Please sign in to comment.