-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(store): decouple waku store public api types from rpc types #1350
Conversation
HistoryErrorKind* {.pure.} = enum | ||
UNKNOWN = uint32(000) | ||
PEER_DIAL_FAILURE = uint32(200) | ||
BAD_RESPONSE = uint32(300) | ||
BAD_REQUEST = uint32(400) | ||
SERVICE_UNAVAILABLE = uint32(503) | ||
|
||
HistoryError* = object | ||
case kind*: HistoryErrorKind | ||
of PEER_DIAL_FAILURE: | ||
address*: string | ||
of BAD_RESPONSE, BAD_REQUEST: | ||
cause*: string | ||
else: | ||
discard | ||
|
||
HistoryResult* = Result[HistoryResponse, HistoryError] | ||
|
||
|
||
proc parse*(T: type HistoryErrorKind, kind: uint32): T = | ||
case kind: | ||
of 000, 200, 300, 400, 503: | ||
HistoryErrorKind(kind) | ||
else: | ||
HistoryErrorKind.UNKNOWN | ||
|
||
proc `$`*(err: HistoryError): string = | ||
case err.kind: | ||
of HistoryErrorKind.PEER_DIAL_FAILURE: | ||
"PEER_DIAL_FAILURE: " & err.address | ||
of HistoryErrorKind.BAD_RESPONSE: | ||
"BAD_RESPONSE: " & err.cause | ||
of HistoryErrorKind.BAD_REQUEST: | ||
"BAD_REQUEST: " & err.cause | ||
of HistoryErrorKind.SERVICE_UNAVAILABLE: | ||
"SERVICE_UNAVAILABLE" | ||
of HistoryErrorKind.UNKNOWN: | ||
"UNKNOWN" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rymnc This is, more or less, how I am envisioning error management in the nwaku
codebase, in case we need to differentiate between error causes. Note the enum and the object variants type (this might remember you Rust's io:Error
🙂 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very clean!!
6d5995b
to
d4a2398
Compare
Jenkins BuildsClick to see older builds (8)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, minor nits!
0bed6ce
to
517d4c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
517d4c5
to
c36dbbb
Compare
The Waku Store protocol wire format will be reworked in the next release. To avoid having to refactor the whole codebase because the RPC types are used everywhere, decoupling the public-facing types from the internal implementation details is a good practice. This should apply to any public-facing API (e.g., c-bindings, REST, JSON-RPC, etc.).
common
module (common to the protocol handler and client)