-
Notifications
You must be signed in to change notification settings - Fork 527
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
Unify RESP error serialization #252
Unify RESP error serialization #252
Conversation
* Some refactoring done in ProcessSlotManage to be able discern failure modes * Also potential unused "errorMessage" in TryResetSlotsState?
* Also flattened control flow where else block is unnecessary * Restore behavior in SETSLOTSRANGE which was affected by TryParseSlots changes
* Well, the ProcessFailoverCommands method
* Now moving back over to Garnet.Server
* Regexing these, no complex control flow to worry about.
Starting to think special casing the generic errors would be a mistake and everything should flow into Having WriteGenericError taking in constants in different format (missing ERR prefix which was added in the write method) would eventually lead to duplication as there are codepaths where non-generic and generic errors are both used. edit: As I'm doing the switchover, it's very clear that this is better approach. For example, StackExchange.Redis exceptions now have the errors in same form as we write them to |
* And switch over to WriteError
* And few simplifications I came across
…essages * Address PR feedback
…garnet into write-generic-resp-error
Fantastic cleanup!! |
Gonna do one more commit where I move more of these constant error strings to |
Sounds good, though try to avoid big PRs since they are hard to review and could result in a lot of conflicts at merge time. |
Yeah.. these tend to get a bit out of hand too easily😬I'll leave the constant as follow-up for anyone to do instead.. |
In #223 @vazois wished to remove the need from callers to format error messages.
In RESP spec, it is said that the serialized errors of the form-ERR [errorMessage]\r\n
are "generic errors". I used this distinction to addWriteGenericError
toRespWriteUtils
.The original plan was to have
WriteGenericError
, which would only take in the error message for the generic errors which are most common. However that specialization would complicate and confuse I abandoned it and instead went for theWriteError
Before this PR all error response serialization happened either by copying the static ASCII encoded error constants or by manually formatting them in the middle of parsing code. The parsing logic often returned a
ROS<byte>
that could either be a simple error or aCmdString.RESP_OK
and used this as the indicator whether an operation was successful or not. Often this returnedROS<byte>
was directly copied to the send buffer. This approach was very error prone, as the caller had to correctly format the error string to start with-
and end with a terminator\r\n
. This was hard to remember and while doing this PR I came across more where this was forgotten or lost during refactors.This PR flows all simple error serialization string to
RespWriteUtils.WriteError
. This requires making the error serialization a separate operation from serializing "+OK\r\n" and such required some adjustments in many method overloads. A common pattern introduced in this PR and that already existed in the project is familiar and intuitivebool TryX(.., out Y value)
pattern from BCL. In majority of the places where we previously returned aROS<byte>
of either error or OK, we now return boolean indicating whether the there was error or not. If there was error (it returned false), we can grab the error string fromout
parameter.