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.hsindex 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 valscase r of- Left e -> pure . (c ,) . Left $ "invalid expression: " <> show e+ Left e -> pure . (c ,) . Left $ renderPrettyDef eRight valsRes -> dotraverse_ (insertExprDB conn name) valslet news = Seq.fromList $ zip vals valsResdiff --git a/src/Radicle/Internal/Core.hs b/src/Radicle/Internal/Core.hsindex 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-- * Valuedata 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 athrowErrorHere = withFrozenCallStack (throwError . LangError [Ann.thisPos])@@ -160,6 +157,7 @@ errorDataToValue e = case e ofNoValue -> 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", [])wheremakeA = quote . Atomdiff --git a/src/Radicle/Internal/HttpStorage.hs b/src/Radicle/Internal/HttpStorage.hsindex 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 -> dores <- 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 sesubmit :: [Value] -> ClientM Valuesubmit = client chainSubmitEndpoint . Valuesdiff --git a/src/Radicle/Internal/Pretty.hs b/src/Radicle/Internal/Pretty.hsindex 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) whereBadBindings 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) ]wherepos :: Int -> Textpos 1 = "1st"diff --git a/src/Radicle/Internal/Storage.hs b/src/Radicle/Internal/Storage.hsindex 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) -> dores <- lift $ send id vcase 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)