-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.py
More file actions
63 lines (44 loc) · 2.27 KB
/
Copy patherrors.py
File metadata and controls
63 lines (44 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""The exceptions komet-node raises internally.
Collected in one module so no layer has to reach into another purely for an error type
(the encoder, for instance, must not depend on the interpreter just to signal a bad input).
- :class:`NodeInterpreterError` — the K interpreter subprocess failed.
- :class:`TransactionEncodingError` — a Stellar transaction could not be encoded.
- :class:`RpcError` — a JSON-RPC error to hand back to the client.
"""
from __future__ import annotations
class NodeError(RuntimeError):
"""Base class for komet-node's own errors."""
class NodeInterpreterError(NodeError):
"""The K interpreter subprocess failed or produced no usable output."""
class TransactionEncodingError(NodeError):
"""A Stellar transaction could not be encoded into a node request envelope.
Raised by :class:`~komet_node.transaction.TransactionEncoder` for inputs it cannot
translate (sub-stroop XLM amounts, malformed strkey addresses). On the admission path
the server catches it and turns it into a ``txMALFORMED`` status response.
"""
class RpcError(Exception):
"""A JSON-RPC error to return to the client, carrying its spec code and message.
Raised by request validation and dispatch in the server so the envelope builders can
return a single value type instead of threading a pre-formatted error string back
through their return type. :meth:`~komet_node.server.StellarRpcServer.handle_rpc`
catches it and formats the error envelope. The classmethods name the JSON-RPC 2.0
error codes; ``invalid_params`` prepends the conventional ``Invalid params:`` prefix.
"""
code: int
message: str
def __init__(self, code: int, message: str) -> None:
super().__init__(code, message)
self.code = code
self.message = message
@classmethod
def invalid_request(cls, message: str) -> RpcError:
return cls(-32600, message)
@classmethod
def invalid_params(cls, detail: str) -> RpcError:
return cls(-32602, f'Invalid params: {detail}')
@classmethod
def method_not_found(cls, message: str = 'Method not found') -> RpcError:
return cls(-32601, message)
@classmethod
def internal(cls, message: str = 'Internal error') -> RpcError:
return cls(-32603, message)