-
Notifications
You must be signed in to change notification settings - Fork 107
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
Add Err() function to Response for detailed errors #246
Conversation
0a39d49
to
1a28767
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.
I like this a lot! Let's add something to USER_GUIDE too?
6ada302
to
a9137e0
Compare
a9137e0
to
531d416
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.
I think we're close, but something feels wrong about having to now check for error twice. WDYT?
os.Exit(1) | ||
} | ||
if err := searchResponse.Err(); err != nil { | ||
fmt.Println(fmt.Sprintf("failed to search document: %s", err)) | ||
} |
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 think this is net worse than what we had - we now have to check for error twice? Shouldn't err
the first time be what we put into searchResponse.Err()
?
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.
Yes and nope.
When doing the request the .Do
function returns the response and an error. For example this Cat request. The returned error from .Do
is most likely a network error or something with the request it self.
Compared to the Err()
function which checks the actual returned response for errors. If you wanted do this in an single error check, you would need to use the .Err()
function in each .Do()
function, as right now the .Do
functions does not care about the actual 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.
That's what I am saying, shouldn't we make .Do
care about the actual response?
As a user I want to write this:
createIndexResponse, err := createIndex.Do(context.Background(), client)
if err != nil {
// err here is either a network error, or the error from the response
fmt.Println(fmt.Sprintf("failed to create index: %s", err))
os.Exit(1)
}
WDYT?
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.
Depends on what the lib maintainers wants.
Pro:
- The lib has a standard way on handling response errors, which prevent other users from doing it by them self
- You only need to check one error
- Adds the possibility to have a custom error type for some requests
- Would make it easier for beginners to use the lib as the don´t need to handle the errors by them self
Cons:
- Existing users with their own implementation needs to check the returned error. For example if the status code 404 is accepted. Currently this would be an error. Otherwise the question turns up, if the accepted response code should be a config setting to each Do request?
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.
main...Jakob3xD:opensearch-go:opensearchapi-response-error
Still missing some stuff but this is how it could look like.
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 like the pros and I like the implementation. The fact that it's easier for beginners is huge.
Is this (the con) a breaking change for existing users? If so we'll need to major increment the version of the client.
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.
IMO this would be a braking change as users that did not care about the response code will now get errors they need to handle.
I will drop the current commits and cherry-pick the commits of my other branch into this after some more USER_GUIDE improvements. I want/need to add an example of the error handling.
835b0dc
to
b028a9a
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.
This is so much better!
Let's add an UPGRADING.md like in #237?
Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>
Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>
Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>
Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>
Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>
Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>
Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>
Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>
Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>
Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>
Reading https://github.com/opensearch-project/opensearch-go/blob/main/UPGRADING.md#opensearchapi-error-handling I think we didn't do the best job explaining how before/after for error handling changed. You had to do |
@Jakob3xD I tried sending you an e-mail about something, maybe it went to spam? :) mind dropping me a note to dblock[at]dblock[dot]org or dblock[at]amazon[dot]com? Thaaanks! |
Closes #220 |
There might have been something amiss in the way we updated the user guide. A user has run into a compilation issue with the Error type: https://forum.opensearch.org/t/ide-doesnt-see-error-type-in-opensearch-go-example/14224 |
Might just be an older client version @wbeckler. |
…ensearch-project#246)" This reverts commit 8d3cf4d. Signed-off-by: Vacha Shah <vachshah@amazon.com>
#322) * Revert "Draft: Add Err() function to Response for detailed errors (#246)" This reverts commit 8d3cf4d. Signed-off-by: Vacha Shah <vachshah@amazon.com> * Fixing PIT APIs introduced in PR #253 since they use response.Err() Signed-off-by: Vacha Shah <vachshah@amazon.com> * Removing opensearchapi.Error usage from snapshot tests introduced in PR #237 Signed-off-by: Vacha Shah <vachshah@amazon.com> * Resolve Changelog conflicts Signed-off-by: Vacha Shah <vachshah@amazon.com> --------- Signed-off-by: Vacha Shah <vachshah@amazon.com>
@Xe ranted about the ES client in https://xeiaso.net/blog/elasticsearch - I think we fixed the error handling part fully in this PR, @Jakob3xD care to take a look at the blog post? anything I've missed? |
I wouldn't say we cover it fully. In Go it is common to have pre-defined error types that you can match on. So for example you have the error type ErrIndexNotFound which the user can then use to match against his error. But as this is hard to maintain our implementation is more generic but at least existing 😅. We do the json to go part for the user and return one error so you don't need to check the response for errors your self. Beside that I can understand his anger. That's why I want to rework the lib to make it more idiomatic. |
Please! |
Was this PR reverted? Not seeing it in main or the 2.3 release. |
Yeah, but I don't know what happened here, @VachaShah? |
Thats weird, I don't see this commit but no revert happened for this as well. Taking a deeper look. |
Was this supposed to be a breaking change? |
2f58bf6 but that's on 2.3 - I guess because it was a breaking change |
It's on main though, but was reverted from 2.3 as breaking? |
Yeah I reverted before 2.3 release since this was a breaking change to do the next 2.x release. |
opensearch-project#322) * Revert "Draft: Add Err() function to Response for detailed errors (opensearch-project#246)" This reverts commit 8d3cf4d. Signed-off-by: Vacha Shah <vachshah@amazon.com> * Fixing PIT APIs introduced in PR opensearch-project#253 since they use response.Err() Signed-off-by: Vacha Shah <vachshah@amazon.com> * Removing opensearchapi.Error usage from snapshot tests introduced in PR opensearch-project#237 Signed-off-by: Vacha Shah <vachshah@amazon.com> * Resolve Changelog conflicts Signed-off-by: Vacha Shah <vachshah@amazon.com> --------- Signed-off-by: Vacha Shah <vachshah@amazon.com>
#322) (#384) * Revert "Draft: Add Err() function to Response for detailed errors (#246)" This reverts commit 8d3cf4d. * Fixing PIT APIs introduced in PR #253 since they use response.Err() * Removing opensearchapi.Error usage from snapshot tests introduced in PR #237 * Resolve Changelog conflicts --------- Signed-off-by: Vacha Shah <vachshah@amazon.com>
Description
Add Err() function to Response and a new Error Type for a better and more detailed error handling.
Issues Resolved
Related #220
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.