Skip to content

A peer-to-peer stack for code collaboration

Better remote server send! errors (#301)

James Haydon1fee45c9d937
diff --git a/exe/Server.hs b/exe/Server.hs
index 4407503..9b5810c 100644
--- a/exe/Server.hs
+++ b/exe/Server.hs
@@ -84,7 +84,7 @@ insertExpr conn chains name vals = modifyMVar (getChains chains) $ \c -> do
$ runLang (chainState chain)
$ traverse eval vals
case r of
- Left e -> pure . (c ,) . Left $ "invalid expression: " <> show e
+ Left e -> pure . (c ,) . Left $ renderPrettyDef e
Right valsRes -> do
traverse_ (insertExprDB conn name) vals
let news = Seq.fromList $ zip vals valsRes
diff --git a/src/Radicle/Internal/Core.hs b/src/Radicle/Internal/Core.hs
index 868256a..2b50672 100644
--- a/src/Radicle/Internal/Core.hs
+++ b/src/Radicle/Internal/Core.hs
@@ -45,9 +45,7 @@ import qualified Radicle.Internal.Type as Type
-- * Value
data LangError r = LangError [Ann.SrcPos] (LangErrorData r)
- deriving (Eq, Show, Read, Generic, Functor)
-
-instance Serialise r => Serialise (LangError r)
+ deriving (Eq, Show, Generic, Functor)
data PatternMatchError
= NoMatch
@@ -85,12 +83,11 @@ data LangErrorData r =
-- | Raised if @(throw ident value)@ is evaluated. Arguments are
-- provided by the call to @throw@.
| ThrownError Ident r
+ | SendError Text
| PatternMatchError PatternMatchError
-- | Raised if the effectful @exit!@ primitive is evaluated.
| Exit
- deriving (Eq, Show, Read, Generic, Functor)
-
-instance Serialise r => Serialise (LangErrorData r)
+ deriving (Eq, Show, Generic, Functor)
throwErrorHere :: (MonadError (LangError Value) m, HasCallStack) => LangErrorData Value -> m a
throwErrorHere = withFrozenCallStack (throwError . LangError [Ann.thisPos])
@@ -160,6 +157,7 @@ errorDataToValue e = case e of
NoValue -> makeVal ( "no-value-to-match", [])
NoMatch -> makeVal ( "non-exhaustive-pattern-matches", [])
BadBindings p -> makeVal ( "bad-pattern", [("bad-pattern", p)])
+ SendError se -> makeVal ( "send-error", [("info", String se)] )
Exit -> makeVal ("exit", [])
where
makeA = quote . Atom
diff --git a/src/Radicle/Internal/HttpStorage.hs b/src/Radicle/Internal/HttpStorage.hs
index 8216e56..3795e46 100644
--- a/src/Radicle/Internal/HttpStorage.hs
+++ b/src/Radicle/Internal/HttpStorage.hs
@@ -94,9 +94,7 @@ httpStoragePrimFns' mgr =
\ chain located at the URL for evaluation."
, \url values -> do
res <- liftIO $ runClientM' url mgr (submit $ toList values)
- pure $ case res of
- Left servantError -> Left $ show servantError
- Right _ -> Right ()
+ pure $ bimap fmtError (const ()) res
)
, storageReceive =
( "receive!"
@@ -107,6 +105,11 @@ httpStoragePrimFns' mgr =
pure $ first show res
)
}
+ where
+ fmtError = \case
+ FailureResponse Response{..} ->
+ "status code: " <> show (fromEnum responseStatusCode) <> "\n" <> toS responseBody
+ se -> show se
submit :: [Value] -> ClientM Value
submit = client chainSubmitEndpoint . Values
diff --git a/src/Radicle/Internal/Pretty.hs b/src/Radicle/Internal/Pretty.hs
index 73c859e..1cc8337 100644
--- a/src/Radicle/Internal/Pretty.hs
+++ b/src/Radicle/Internal/Pretty.hs
@@ -123,6 +123,9 @@ instance PrettyV r => PrettyV (LangErrorData r) where
BadBindings p -> "Faulty pattern function. Pattern functions must return\
\ `[:just b]` where `b` is a dict of new bindings (from\
\ atoms to values), or `:nothing`:" <+> prettyV p
+ SendError se -> vsep
+ [ "send!: There was en error sending expressions to a remote:"
+ , indent 2 (pretty se) ]
where
pos :: Int -> Text
pos 1 = "1st"
diff --git a/src/Radicle/Internal/Storage.hs b/src/Radicle/Internal/Storage.hs
index 221e2a4..09ed60a 100644
--- a/src/Radicle/Internal/Storage.hs
+++ b/src/Radicle/Internal/Storage.hs
@@ -53,9 +53,8 @@ buildStoragePrimFns backend =
(String id, Vec v) -> do
res <- lift $ send id v
case res of
- Left e -> throwErrorHere . OtherError
- $ sendName <> ": failed:" <> show e
- Right _ -> pure $ Keyword $ unsafeToIdent "ok"
+ Left e -> throwErrorHere (SendError e)
+ Right _ -> pure $ Keyword $ unsafeToIdent "ok"
(String _, v) -> throwErrorHere $ TypeError sendName 1 TVec v
(v, _) -> throwErrorHere $ TypeError sendName 0 TString v
)