-
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
Adding error message to the History Responses #660
Conversation
Jenkins BuildsClick to see older builds (3)
|
@@ -299,20 +305,13 @@ proc paginateWithIndex*(list: seq[IndexedWakuMessage], pinfo: PagingInfo): (seq[ | |||
newCursor = msgList[s].index # the new cursor points to the begining of the page | |||
|
|||
if (retrievedPageSize == 0): | |||
return (@[], PagingInfo(pageSize: 0, cursor:pinfo.cursor, direction: pinfo.direction)) | |||
return (@[], PagingInfo(pageSize: 0, cursor:pinfo.cursor, direction: pinfo.direction), HistoryResponseError.OK) |
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.
What is HistoryResponseError.OK? Seems like an oxymoron, isn't 0 pages retrieved, if correct, an OK response?
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.
The goal of the error message is to distinguish between two cases that both result in 0 message history. 1) when the cursor is invalid 2) the cursor is valid but there is no match for the submitted query
When an error message is OK, it means the second scenario happened. Having zero messages in the response is not by itself an error, but if it is because of an invalid cursor then it is an error (as the input is invalid).
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.
Following @jm-clius comment #660 (comment), I have renamed OK to NONE to resolve the naming ambiguity.
@@ -52,9 +52,15 @@ type | |||
startTime*: float64 # used for time-window query | |||
endTime*: float64 # used for time-window query | |||
|
|||
HistoryResponseError* {.pure.} = enum | |||
## HistoryResponseError contains error message to inform the querying node about the state of its request | |||
OK = uint32(0) |
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.
Why is this an 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.
I'd suggest making this NONE
and the default. That way we're not mixing "Success" and "Error" codes (which should be avoided) and don't have to use it other than for error conditions.
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.
Sure, that makes sense. I will change its name to none!
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.
OK means no error, and I agree that NONE makes more sense! @oskarth
I might be missing some context, but to me:
means we need give error for invalid cursors. If topic field doesn't match, then seems like an OK response and not an error? Perhaps informational, as in "no messages for topic". What do other standard APIs do in this scenario? |
@@ -245,7 +251,7 @@ proc findIndex*(msgList: seq[IndexedWakuMessage], index: Index): Option[int] = | |||
return some(i) | |||
return none(int) | |||
|
|||
proc paginateWithIndex*(list: seq[IndexedWakuMessage], pinfo: PagingInfo): (seq[IndexedWakuMessage], PagingInfo) = | |||
proc paginate*(list: seq[IndexedWakuMessage], pinfo: PagingInfo): (seq[IndexedWakuMessage], PagingInfo, HistoryResponseError) = |
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.
Perhaps if this defaults to OK
I imagine you wouldn't have to explicitly set HistoryResponseError.OK
in so many places?
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.
The default is OK, however, as part of the unit testing, I need to check that the different execution paths of paginate
that yield OK behave as expected and do not produce an error.
Please let me know if there is a specific part of the code that the use of OK is unnecessary and can be avoided.
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.
BTW, as I am using return
to terminate the proc, I cannot leave the third output value unspecified.
@oskarth I also checked Twitter pagination, it appears they do not consider any error message for invalid cursors/tokens https://developer.twitter.com/en/docs/twitter-api/pagination |
@oskarth Let me know if further error messages is desired |
HistoryResponse* = object | ||
messages*: seq[WakuMessage] | ||
pagingInfo*: PagingInfo # used for pagination | ||
error*: HistoryResponseError |
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.
Maybe I'm still missing something, but if HistoryResponseError
is NONE
, couldn't that intent be communicated with error*: Option[HistoryResponsError]
? Right now, the way I'm reading it, it seems like an ad-hoc implementation of Option
type.
That way in case of empty result, error would simply be omitted. What am I missing with this approach?
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.
In protobuf terms, that field would be emitted, so the equivalent thing (0
) would go over the wire, I believe.
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.
Maybe I'm still missing something, but if HistoryResponseError is NONE, couldn't that intent be communicated with error*: Option[HistoryResponsError]? Right now, the way I'm reading it, it seems like an ad-hoc implementation of Option type.
If we want the have error codes for a successful response, then the error
field should not be optional. Otherwise, this can be converted to an optional field.
I suggest not to make the error
field optional (although in protobuf fields are optional by default). The reason is to make sure that the error
is not omitted by mistake rather the response has indeed been concluded successfully.
Let me know whether this makes sense or shall I convert it to optional (or make it a simple string error). I'll follow your discretion.
See comment above re possibly using
Generally an extensible way of dealing with this is to have an optional error string, that way things can be elaborated on without a protocol upgrade. This helps with logs and debugging, for example if further down the line you want errors like "permission denied" "rate limiting reached (300/500)" or the "foobar not found" you suggested. It can be complemented with an error code, like 404, 500 etc in HTTP, for more automatic error handling but for now I think knowing 1) It is an error 2) Invalid cursor is good enough! |
As for what error are needed now, might make sense to get @richard-ramos @siphiuel POV in terms of what Core/Desktop needs |
Thanks for the comments @oskarth! As in the case of the HTTP response status codes, there are plenty of options covering a successful response like 200 OK. |
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.
Let's get this merged, if we want to tweak it at a later point it shouldn't be an issue. Thanks for the patience!
Sure! thanks for the comments @oskarth , definitely please let me know if further updates would be required to make the error handling more effective and useful! :) |
This closes vacp2p/rfc#248 and is incremental progress towards vacp2p/rfc#406.
I also utilized this PR to do some clean-up on the pagination logic as part of #484. Removed the private proc
paginateWithoutIndex
and shifted its code inside thefindMessage
proc for the sake of better code readability. Moreover, thepaginateWithoutIndex
had simple logic i.e., peeling off theIndex
fromIndexedWakuMessages
, so having it as a separate proc would only complicate the code. Following this change, I have renamed another existing proc i.e.,paginateWithIndex
topaginate
.Also, replaced the use of
Result
with the explicitreturn
call (as suggested in track 1 checklist of the refactor week https://hackmd.io/1imOGULZRsed2HpgmzGleA).