Skip to content

Commit

Permalink
Throwing more specific Exception on failure to retrieve result. (#166)
Browse files Browse the repository at this point in the history
* Making the keypair hashable, and moving setters out of property functions

* Fixing linter error

* Fixing docstring error

* Additional Exceptions for more specific exception handeling, small syntaxt updates

Co-authored-by: FFEvan <evan.owen@firstfoundry.co>
  • Loading branch information
ulmentflam and FFEvan committed Jan 7, 2022
1 parent 07ec29e commit f996c07
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
9 changes: 6 additions & 3 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ function-naming-style=snake_case
good-names=i,
j,
k,
e,
x,
m,
ex,
Run,
_
Expand Down Expand Up @@ -557,7 +560,7 @@ valid-metaclass-classmethod-first-arg=cls
[DESIGN]

# Maximum number of arguments for function / method.
max-args=5
max-args=7

# Maximum number of attributes for a class (see R0902).
max-attributes=7
Expand All @@ -566,7 +569,7 @@ max-attributes=7
max-bool-expr=5

# Maximum number of branch for function / method body.
max-branches=12
max-branches=25

# Maximum number of locals for function / method body.
max-locals=15
Expand All @@ -581,7 +584,7 @@ max-public-methods=20
max-returns=6

# Maximum number of statements in function / method body.
max-statements=50
max-statements=70

# Minimum number of public methods for a class (see R0903).
min-public-methods=2
Expand Down
14 changes: 9 additions & 5 deletions src/solana/rpc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class RPCException(Exception):
"""Raised when RPC method returns an error result."""


class RPCNoResultException(Exception):
"""Raised when an RPC method returns no result."""


class UnconfirmedTxError(Exception):
"""Raise when confirming a transaction times out."""

Expand Down Expand Up @@ -400,17 +404,17 @@ def _set_log_filter_args(log_filter: str) -> Tuple[types.RPCMethod, str]:

@staticmethod
def _post_send(resp: types.RPCResponse) -> types.RPCResponse:
maybe_error = resp.get("error")
if maybe_error is not None:
raise RPCException(maybe_error)
error = resp.get("error")
if error:
raise RPCException(error)
if not resp.get("result"):
raise Exception("Failed to send transaction")
raise RPCNoResultException("Failed to send transaction")
return resp

@staticmethod
def parse_recent_blockhash(blockhash_resp: types.RPCResponse) -> Blockhash:
"""Extract blockhash from JSON RPC result."""
if not blockhash_resp["result"]:
if not blockhash_resp.get("result"):
raise RuntimeError("failed to get recent blockhash")
return Blockhash(blockhash_resp["result"]["value"]["blockhash"])

Expand Down

0 comments on commit f996c07

Please sign in to comment.