module Morley.Client.RPC.Error
( ClientRpcError (..)
, RunCodeErrors (..)
, UnexpectedErrors (..)
, IncorrectRpcResponse (..)
, WaitForOperationError (..)
) where
import Fmt (Buildable(..), blockListF, pretty, (+|), (|+))
import Morley.Micheline (Expression)
import Morley.Tezos.Address
import Morley.Client.RPC.Types
data ClientRpcError
= ContractFailed
ContractAddress
Expression
| BadParameter
Address
Expression
| EmptyTransaction
ImplicitAddress
| ShiftOverflow
ContractAddress
| GasExhaustion
ContractAddress
| KeyAlreadyRevealed
ImplicitAddress
| DelegateNotRegistered
ImplicitAddress
| ClientInternalError
InternalError
deriving stock Int -> ClientRpcError -> ShowS
[ClientRpcError] -> ShowS
ClientRpcError -> String
(Int -> ClientRpcError -> ShowS)
-> (ClientRpcError -> String)
-> ([ClientRpcError] -> ShowS)
-> Show ClientRpcError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ClientRpcError] -> ShowS
$cshowList :: [ClientRpcError] -> ShowS
show :: ClientRpcError -> String
$cshow :: ClientRpcError -> String
showsPrec :: Int -> ClientRpcError -> ShowS
$cshowsPrec :: Int -> ClientRpcError -> ShowS
Show
instance Buildable ClientRpcError where
build :: ClientRpcError -> Builder
build = \case
ContractFailed ContractAddress
addr Expression
expr ->
Builder
"The execution of the smart contract " Builder -> Builder -> Builder
forall b. FromBuilder b => Builder -> Builder -> b
+| ContractAddress
addr ContractAddress -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+
Builder
" failed with " Builder -> Builder -> Builder
forall b. FromBuilder b => Builder -> Builder -> b
+| Expression
expr Expression -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
""
BadParameter Address
addr Expression
expr ->
Builder
"Parameter " Builder -> Builder -> Builder
forall b. FromBuilder b => Builder -> Builder -> b
+| Expression
expr Expression -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
" does not match the type of " Builder -> Builder -> Builder
forall b. FromBuilder b => Builder -> Builder -> b
+| Address
addr Address -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
"."
EmptyTransaction ImplicitAddress
addr -> RunError -> Builder
forall p. Buildable p => p -> Builder
build (ImplicitAddress -> RunError
REEmptyTransaction ImplicitAddress
addr)
ShiftOverflow ContractAddress
addr -> ContractAddress
addr ContractAddress -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
" failed due to shift overflow"
GasExhaustion ContractAddress
addr -> ContractAddress
addr ContractAddress -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
" failed due to gas exhaustion"
KeyAlreadyRevealed ImplicitAddress
addr -> Builder
"Key for " Builder -> Builder -> Builder
forall b. FromBuilder b => Builder -> Builder -> b
+| ImplicitAddress
addr ImplicitAddress -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
" has already been revealed"
DelegateNotRegistered ImplicitAddress
addr -> ImplicitAddress
addr ImplicitAddress -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
" not registered as delegate"
ClientInternalError InternalError
err -> InternalError -> Builder
forall p. Buildable p => p -> Builder
build InternalError
err
instance Exception ClientRpcError where
displayException :: ClientRpcError -> String
displayException = ClientRpcError -> String
forall a b. (Buildable a, FromBuilder b) => a -> b
pretty
data RunCodeErrors = RunCodeErrors [RunError]
deriving stock Int -> RunCodeErrors -> ShowS
[RunCodeErrors] -> ShowS
RunCodeErrors -> String
(Int -> RunCodeErrors -> ShowS)
-> (RunCodeErrors -> String)
-> ([RunCodeErrors] -> ShowS)
-> Show RunCodeErrors
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RunCodeErrors] -> ShowS
$cshowList :: [RunCodeErrors] -> ShowS
show :: RunCodeErrors -> String
$cshow :: RunCodeErrors -> String
showsPrec :: Int -> RunCodeErrors -> ShowS
$cshowsPrec :: Int -> RunCodeErrors -> ShowS
Show
instance Buildable RunCodeErrors where
build :: RunCodeErrors -> Builder
build (RunCodeErrors [RunError]
errs) = Builder
"'run_code' failed with the following errors: " Builder -> Builder -> Builder
forall b. FromBuilder b => Builder -> Builder -> b
+|
[RunError] -> Builder
forall (f :: * -> *) a. (Foldable f, Buildable a) => f a -> Builder
blockListF [RunError]
errs Builder -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
""
instance Exception RunCodeErrors where
displayException :: RunCodeErrors -> String
displayException = RunCodeErrors -> String
forall a b. (Buildable a, FromBuilder b) => a -> b
pretty
data UnexpectedErrors
= UnexpectedRunErrors [RunError]
| UnexpectedInternalErrors [InternalError]
deriving stock (Int -> UnexpectedErrors -> ShowS
[UnexpectedErrors] -> ShowS
UnexpectedErrors -> String
(Int -> UnexpectedErrors -> ShowS)
-> (UnexpectedErrors -> String)
-> ([UnexpectedErrors] -> ShowS)
-> Show UnexpectedErrors
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UnexpectedErrors] -> ShowS
$cshowList :: [UnexpectedErrors] -> ShowS
show :: UnexpectedErrors -> String
$cshow :: UnexpectedErrors -> String
showsPrec :: Int -> UnexpectedErrors -> ShowS
$cshowsPrec :: Int -> UnexpectedErrors -> ShowS
Show)
instance Buildable UnexpectedErrors where
build :: UnexpectedErrors -> Builder
build = \case
UnexpectedRunErrors [RunError]
errs ->
Builder
"Preapply failed due to the following errors:\n" Builder -> Builder -> Builder
forall b. FromBuilder b => Builder -> Builder -> b
+|
[Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat ((RunError -> Builder) -> [RunError] -> [Builder]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map ((Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"\n\n") (Builder -> Builder)
-> (RunError -> Builder) -> RunError -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RunError -> Builder
forall p. Buildable p => p -> Builder
build) [RunError]
errs) Builder -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
""
UnexpectedInternalErrors [InternalError]
errs ->
Builder
"RPC failed with unexpected internal errors:\n" Builder -> Builder -> Builder
forall b. FromBuilder b => Builder -> Builder -> b
+|
[Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat ((InternalError -> Builder) -> [InternalError] -> [Builder]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map ((Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"\n\n") (Builder -> Builder)
-> (InternalError -> Builder) -> InternalError -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InternalError -> Builder
forall p. Buildable p => p -> Builder
build) [InternalError]
errs) Builder -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
""
instance Exception UnexpectedErrors where
displayException :: UnexpectedErrors -> String
displayException = UnexpectedErrors -> String
forall a b. (Buildable a, FromBuilder b) => a -> b
pretty
data IncorrectRpcResponse
= RpcUnexpectedSize Int Int
| RpcOriginatedNoContracts
| RpcOriginatedMoreContracts [ContractAddress]
deriving stock Int -> IncorrectRpcResponse -> ShowS
[IncorrectRpcResponse] -> ShowS
IncorrectRpcResponse -> String
(Int -> IncorrectRpcResponse -> ShowS)
-> (IncorrectRpcResponse -> String)
-> ([IncorrectRpcResponse] -> ShowS)
-> Show IncorrectRpcResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IncorrectRpcResponse] -> ShowS
$cshowList :: [IncorrectRpcResponse] -> ShowS
show :: IncorrectRpcResponse -> String
$cshow :: IncorrectRpcResponse -> String
showsPrec :: Int -> IncorrectRpcResponse -> ShowS
$cshowsPrec :: Int -> IncorrectRpcResponse -> ShowS
Show
instance Buildable IncorrectRpcResponse where
build :: IncorrectRpcResponse -> Builder
build = \case
RpcUnexpectedSize Int
expected Int
got ->
Builder
"An RPC call returned a list that has " Builder -> Builder -> Builder
forall b. FromBuilder b => Builder -> Builder -> b
+| Int
got Int -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+
Builder
" items, but we expected to get " Builder -> Builder -> Builder
forall b. FromBuilder b => Builder -> Builder -> b
+| Int
expected Int -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
" results"
RpcOriginatedMoreContracts [ContractAddress]
addresses ->
Builder
"Operation expected to originate one contract, but will more:\n" Builder -> Builder -> Builder
forall b. FromBuilder b => Builder -> Builder -> b
+|
[Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat ((ContractAddress -> Builder) -> [ContractAddress] -> [Builder]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map ((Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"\n") (Builder -> Builder)
-> (ContractAddress -> Builder) -> ContractAddress -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContractAddress -> Builder
forall p. Buildable p => p -> Builder
build) [ContractAddress]
addresses) Builder -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
""
IncorrectRpcResponse
RpcOriginatedNoContracts ->
Builder
"Operation expected to originate a contract, but produced nothing"
instance Exception IncorrectRpcResponse where
displayException :: IncorrectRpcResponse -> String
displayException = IncorrectRpcResponse -> String
forall a b. (Buildable a, FromBuilder b) => a -> b
pretty
data WaitForOperationError
= WaitForOperationBlockout Word
| WaitForOperationStreamingError Text
deriving stock Int -> WaitForOperationError -> ShowS
[WaitForOperationError] -> ShowS
WaitForOperationError -> String
(Int -> WaitForOperationError -> ShowS)
-> (WaitForOperationError -> String)
-> ([WaitForOperationError] -> ShowS)
-> Show WaitForOperationError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WaitForOperationError] -> ShowS
$cshowList :: [WaitForOperationError] -> ShowS
show :: WaitForOperationError -> String
$cshow :: WaitForOperationError -> String
showsPrec :: Int -> WaitForOperationError -> ShowS
$cshowsPrec :: Int -> WaitForOperationError -> ShowS
Show
instance Buildable WaitForOperationError where
build :: WaitForOperationError -> Builder
build = \case
WaitForOperationBlockout Word
n -> Builder
"Operation not included after " Builder -> Builder -> Builder
forall b. FromBuilder b => Builder -> Builder -> b
+| Word
n Word -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
" blocks"
WaitForOperationStreamingError Text
s ->
Builder
"Streaming error received waiting for operation: " Builder -> Builder -> Builder
forall b. FromBuilder b => Builder -> Builder -> b
+| Text
s Text -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
""
instance Exception WaitForOperationError where
displayException :: WaitForOperationError -> String
displayException = WaitForOperationError -> String
forall a b. (Buildable a, FromBuilder b) => a -> b
pretty