Conversation
3f93c44 to
e3c77f4
Compare
|
I am working on leveraging errors.Unwrap, which should bring the same benefits: #2906 |
|
I completely agree that (RequestOpts).ContextError must go, since error unwrapping should provide the same capability in a more idiomatic way. I am finding myself in deeper a rabbit hole than I can handle with #2906. I am abandoning it. If this change fits your needs, then I'd be inclined to merge your pull request (this one). |
|
@gophercloud/core what do you think? |
|
We'd have to turn some |
mandre
left a comment
There was a problem hiding this comment.
I'm very much in favor of this change as it makes consuming gophercloud easier.
|
@majewsky Can you please rebase? I think we can then merge 🚀 |
e3c77f4 to
48f1053
Compare
|
rebase done |
|
hmm what happened to the CI |
|
@majewsky something wrong happened on the Github side. When checking out this branch locally, I get the old commits and not the ones you just force-pushed. Do you mind |
48f1053 to
7bc5fd0
Compare
7bc5fd0 to
576938d
Compare
|
I rebased as requested three weeks ago, but apparently this was not seen (maybe because I did not also comment "done"?). Because new merge conflicts have arisen, I have rebased again. |
576938d to
9d56cba
Compare
|
Rebased onto current master to match 2.0.0-beta.4. Please take another look. |
|
There's a failed conflict resolution in |
This is a breaking change intended for the v2.0 release. Rationale: The ErrDefault series of types (ErrDefault400, ErrDefault401, etc.) serve the apparent purpose of allowing to assert on a specific response code (e.g. to handle 404 responses differently from other 4xx/5xx responses). However, because of their design, they often tend to obscure the real underlying error message in many cases, reporting just something like "Method not allowed" instead of the default error string on ErrUnexpectedResponseCode that explains which request failed and includes the actual error message returned by the OpenStack service. This commit removes the types, and all of the associated boilerplate, and replaces them with a single small helper function for quickly asserting that an error is an ErrUnexpectedResponseCode with a specific response code. This also gets rid of the undocumented and untested ProviderClient.ErrorContext interface that I have legitimately no idea what it's supposed to be good for, besides maybe skipping the generation of ErrDefaultXXX-type errors.
This includes a backwards-incompatible change to the error message returned by ErrUnexpectedResponseCode. Error messages are not supposed to contain line breaks because several logging systems do not handle them well (e.g. syslog and fluentd), so we try at least a little bit to get rid of them.
9d56cba to
c4d6bce
Compare
|
Whoopsie, that one probably slipped through last week. Fixed now. |
|
One error remains in a testcase that I did not touch ( |
This is a breaking change intended for the v2.0 release, spun off from the discussion in #2902. I am posting this as a bit of a hot take. If this ends up being a discussion about why the ErrDefaultXXX types and the ErrorContext field are actually useful, and we just end up with actual real documentation on these, that would be a good outcome as well.
Overview and rationale
The ErrDefault series of types (ErrDefault400, ErrDefault401, etc.) serve the apparent purpose of allowing to assert on a specific response code (e.g. to handle 404 responses differently from other 4xx/5xx responses). However, because of their design, they often tend to obscure the real underlying error message in many cases, reporting just something like "Method not allowed" instead of the default error string on ErrUnexpectedResponseCode that explains which request failed and includes the actual error message returned by the OpenStack service. A minimal change to fix that would be to make them all generate the same error string as ErrUnexpectedResponseCode, but there is a much easier solution if we allow the change to be properly breaking.
This commit removes the types, and all of the associated boilerplate, and replaces them with a single small helper function for quickly asserting that an error is an ErrUnexpectedResponseCode with a specific response code. A similar design has been in productive use in my Swift client library for several years. The changes to tests demonstrate how to use this function.
This also gets rid of the undocumented and untested ProviderClient.ErrorContext interface that I have legitimately no idea what it's supposed to be good for, besides maybe allowing users to skip the generation of ErrDefaultXXX-type errors. If that's the only purpose, that would be yet more incentive to just get rid of them.
Finally, as a small (but still breaking) change, this removes some newlines from the error messages generated by ErrUnexpectedResponseCode. Newlines in error messages cause several log aggregators to choke (e.g. I have seen problems with this myself in syslog and fluentd), so we now try a bit harder to avoid them if possible.
Changelog
As far as I can tell, you compile the changelog as part of the release process, so I did not touch it in the PR. Here's a suggested wording for the respective changelog entries if this gets merged: