A peer-to-peer stack for code collaboration
Add error for IPLD document parse failures
Thomas Scholtes9ee0c680f0c2
diff --git a/src/Radicle/Daemon/Monad.hs b/src/Radicle/Daemon/Monad.hsindex a86978f..3523d27 100644--- a/src/Radicle/Daemon/Monad.hs+++ b/src/Radicle/Daemon/Monad.hs@@ -82,3 +82,5 @@ displayError = \caseIpfsExceptionTimeout apiPath -> ("Timeout communicating with IPFS daemon", [("api-path", apiPath)])IpfsExceptionInvalidResponse url parseError -> ("Cannot parse IPFS daemon response", [("url", url), ("parse-error", parseError)])IpfsExceptionNoDaemon -> ("Cannot connect to the IPFS daemon", [])+ IpfsExceptionIpldParse addr parseError ->+ ("Failed to parse IPLD document ", [("addr", addressToText addr), ("parse-error", parseError)])diff --git a/src/Radicle/Ipfs.hs b/src/Radicle/Ipfs.hsindex 44afce6..ff4b11f 100644--- a/src/Radicle/Ipfs.hs+++ b/src/Radicle/Ipfs.hs@@ -67,16 +67,22 @@ data IpfsException| IpfsExceptionInvalidResponse Text Text-- | The IPFS daemon is not running.| IpfsExceptionNoDaemon+ -- | Failed to parse IPLD document returned by @dag/get@ with+ -- 'Aeson.fromJSON'. First argument is the IPFS address, second argument is+ -- the Aeson parse error.+ | IpfsExceptionIpldParse Address Textderiving (Show)instance Exception IpfsException wheredisplayException e = "ipfs: " <> case e of- IpfsException msg -> toS msg- IpfsExceptionNoDaemon -> "Cannot connect to " <> name- IpfsExceptionInvalidResponse url _ -> "Cannot parse " <> name <> " response for " <> toS url- IpfsExceptionTimeout apiPath -> name <> " took too long to respond for " <> toS apiPath- IpfsExceptionErrResp msg -> toS msg- IpfsExceptionErrRespNoMsg -> name <> " failed with no error message"+ IpfsException msg -> toS msg+ IpfsExceptionNoDaemon -> "Cannot connect to " <> name+ IpfsExceptionInvalidResponse url _ -> "Cannot parse " <> name <> " response for " <> toS url+ IpfsExceptionTimeout apiPath -> name <> " took too long to respond for " <> toS apiPath+ IpfsExceptionErrResp msg -> toS msg+ IpfsExceptionErrRespNoMsg -> name <> " failed with no error message"+ IpfsExceptionIpldParse addr parseError ->+ toS $ "Failed to parse IPLD document " <> addressToText addr <> ": " <> parseErrorwherename = "Radicle IPFS daemon"@@ -253,7 +259,7 @@ dagGet :: FromJSON a => Address -> IO adagGet addr = doresult <- ipfsHttpGet "dag/get" [("arg", addressToText addr)]case Aeson.fromJSON result of- Aeson.Error _ -> throw $ IpfsException $ "Invalid machine log entry at " <> addressToText addr+ Aeson.Error err -> throw $ IpfsExceptionIpldParse addr (toS err)Aeson.Success a -> pure anamePublish :: IpnsId -> Address -> IO ()