Skip to content

Commit

Permalink
Merge pull request #1539 from Plutonomicon/koz/1515
Browse files Browse the repository at this point in the history
Clearer Plutip sub-service failure messages
  • Loading branch information
klntsky authored Sep 27, 2023
2 parents c37ffea + 94c800e commit bbcfc6a
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/Internal/Plutip/Server.purs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Contract.Address (NetworkId(MainnetId))
import Contract.Chain (waitNSlots)
import Contract.Config (defaultSynchronizationParams, defaultTimeParams)
import Contract.Monad (Contract, ContractEnv, liftContractM, runContractInEnv)
import Control.Monad.Error.Class (liftEither)
import Control.Monad.Error.Class (liftEither, throwError)
import Control.Monad.State (State, execState, modify_)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Writer (censor, execWriterT, tell)
Expand Down Expand Up @@ -78,7 +78,7 @@ import Ctl.Internal.Wallet.Key (PrivatePaymentKey(PrivatePaymentKey))
import Data.Array as Array
import Data.Bifunctor (lmap)
import Data.BigInt as BigInt
import Data.Either (Either(Left), either, isLeft)
import Data.Either (Either(Left, Right), either, isLeft)
import Data.Foldable (sum)
import Data.HTTP.Method as Method
import Data.Log.Level (LogLevel)
Expand All @@ -103,7 +103,7 @@ import Effect.Aff.Retry
, recovering
)
import Effect.Class (liftEffect)
import Effect.Exception (error, throw)
import Effect.Exception (error, message, throw)
import Effect.Ref (Ref)
import Effect.Ref as Ref
import Mote (bracket) as Mote
Expand Down Expand Up @@ -271,10 +271,11 @@ startPlutipContractEnv
}
startPlutipContractEnv plutipCfg distr cleanupRef = do
configCheck plutipCfg
startPlutipServer'
ourKey /\ response <- startPlutipCluster'
startOgmios' response
startKupo' response
tryWithReport startPlutipServer' "Could not start Plutip server"
(ourKey /\ response) <- tryWithReport startPlutipCluster'
"Could not start Plutip cluster"
tryWithReport (startOgmios' response) "Could not start Ogmios"
tryWithReport (startKupo' response) "Could not start Kupo"
{ env, printLogs, clearLogs } <- mkContractEnv'
wallets <- mkWallets' env ourKey response
pure
Expand All @@ -284,6 +285,17 @@ startPlutipContractEnv plutipCfg distr cleanupRef = do
, clearLogs
}
where
tryWithReport
:: forall (a :: Type)
. Aff a
-> String
-> Aff a
tryWithReport what prefix = do
result <- try what
case result of
Left err -> throwError $ error $ prefix <> ": " <> message err
Right result' -> pure result'

-- Similar to `Aff.bracket`, except cleanup is pushed onto a stack to be run
-- later.
bracket
Expand Down

0 comments on commit bbcfc6a

Please sign in to comment.