Skip to content
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

Changes for (Add IsParseError() documentation #578) #581

Merged
merged 5 commits into from
Jun 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,17 @@ n, resp, err := client.Do(ctx, cmd).AsFtSearch()
## Command Response Cheatsheet

While the command builder is developer-friendly, the response parser is a little unfriendly. Developers must know what
type of Redis response will be returned from the server beforehand and which parser they should use. Otherwise, it panics.
type of Redis response will be returned from the server beforehand and which parser they should use.

Error Handling:
If an incorrect parser function is chosen, an errParse will be returned. You can use the IsParseErr helper to check for this case.

```golang
// Attempt to parse the response. If a parsing error occurs, check if the error is a parse error and handle it.
if err := client.Do(ctx, client.B().Get().Key("k").Build()).AsInt64(); IsParseErr(err) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err := client.Do(ctx, client.B().Get().Key("k").Build()).AsInt64(); IsParseErr(err) {
if err := client.Do(ctx, client.B().Get().Key("k").Build()).ToArray(); IsParseErr(err) {

Hi @karimalzalek, thank you for fixing the document but your example, GET+AsInt64, will not return an errParse. Maybe using something like ToArray as an example will be less confusing.

Also, could you help us emphasize that a user should normally fix the code by choosing the correct parser function, not using IsParseErr, in the comment?

fmt.Println("Parsing error:", err)
}
```

It is hard to remember what type of message will be returned and which parsing to use. So, here are some common examples:

Expand Down