[go: nahoru, domu]

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

Errors from original http.Client response are double-wrapped when using the RoundTripper #95

Merged
merged 2 commits into from
Jun 9, 2020

Conversation

andrewloux
Copy link
Contributor
@andrewloux andrewloux commented May 19, 2020

When you're using a http.Client with a custom RoundTripper that actually facilitates the retries (it maintains its own internal http.Client object); any errors returned from the original http.Client are re-wrapped.

For instance, trying to do a Get request that returns an error response, and using the PassthroughErrorHandler to return the real failure would result in an error like this:

Get "http://this-url-does-not-exist.com/": Get "http://this-url-does-not-exist.com/": dial tcp: lookup this-url-does-not-exist.com: no such host

This is basically an *url.Error object nested within another *url.Error's Err field.

We can just .Unwrap() it to make sure that we only get what we need. Open to other suggestions though.

@hashicorp-cla
Copy link
hashicorp-cla commented May 19, 2020

CLA assistant check
All committers have signed the CLA.

@andrewloux andrewloux force-pushed the double-wrapping-http-errors branch 2 times, most recently from d82c5cd to 0e0b489 Compare May 19, 2020 18:48
@andrewloux
Copy link
Contributor Author

cc @jefferai - Just wanted to ping a maintainer for some 👀 here.

@andrewloux
Copy link
Contributor Author
andrewloux commented Jun 2, 2020

cc @ryanuber - in case you are able to help here :)

Ah, just realized your wrote the RoundTripper here, so probably perfect for you.

@jefferai
Copy link
Member
jefferai commented Jun 2, 2020

@andrewlouis93 at the moment no reviews can proceed since you have not signed the CLA.

…ng the custom RoundTripper

only proceed with the unwrapped error if it can be unwapped

normalize error
@andrewloux andrewloux force-pushed the double-wrapping-http-errors branch from 0e0b489 to 030fba5 Compare June 2, 2020 18:37
@andrewloux
Copy link
Contributor Author

@jefferai Done, had committed this with a different email attached

@jefferai
Copy link
Member
jefferai commented Jun 3, 2020

I think this looks good -- do you know if this is only an issue with *url.Error? Basically I'm wondering if it's worth asserting before unilaterally unwrapping or if this will always be problematic.

@andrewloux
Copy link
Contributor Author
andrewloux commented Jun 8, 2020

@jefferai That's a good consideration. In this case yes, but only because Do in the standard library only ever returns *url.Error; and the standard library Do invocations wind up getting nested under each other.

We can be a bit more strict here and only unwrap if the error is an *url.Error; so we do not nest it again.

Just updated and left some comments, take a look and let me know what you think.

@andrewloux andrewloux force-pushed the double-wrapping-http-errors branch from 7315ade to 0b5a47c Compare June 8, 2020 12:55
@jefferai
Copy link
Member
jefferai commented Jun 9, 2020

LGTM, thanks!

@jefferai jefferai merged commit 7cf40fa into hashicorp:master Jun 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants