Skip to content

Commit

Permalink
Backend/Ether: refactor some error handling to avoid repetition
Browse files Browse the repository at this point in the history
And at the same time hopefully we workaround a fantomas bug which might
be tricky to fix: fsprojects/fantomas#1390
  • Loading branch information
knocte committed Jan 27, 2021
1 parent 47dfaf6 commit faa6825
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/GWallet.Backend/Ether/EtherServer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,21 @@ module Server =
| _ ->
()

let private err32kPossibleMessages =
[
"pruning=archive"
"header not found"
"error: no suitable peers available"
"missing trie node"
]

let MaybeRethrowRpcResponseException (ex: Exception): unit =
let maybeRpcResponseEx = FSharpUtil.FindException<JsonRpcSharp.Client.RpcResponseException> ex
match maybeRpcResponseEx with
| Some rpcResponseEx ->
if rpcResponseEx.RpcError <> null then
if rpcResponseEx.RpcError.Code = int RpcErrorCode.StatePruningNodeOrMissingTrieNodeOrHeaderNotFound then
if (not (rpcResponseEx.RpcError.Message.Contains "pruning=archive")) &&
(not (rpcResponseEx.RpcError.Message.Contains "header not found")) &&
(not (rpcResponseEx.RpcError.Message.Contains "error: no suitable peers available")) &&
(not (rpcResponseEx.RpcError.Message.Contains "missing trie node")) then
if not (err32kPossibleMessages.Any (fun msg -> rpcResponseEx.RpcError.Message.Contains msg)) then
raise <| Exception(
SPrintF2 "Expecting 'pruning=archive' or 'missing trie node' or 'error: no suitable peers available' or 'header not found' in message of a %d code, but got '%s'"
(int RpcErrorCode.StatePruningNodeOrMissingTrieNodeOrHeaderNotFound)
Expand Down

0 comments on commit faa6825

Please sign in to comment.