Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upAdds WriteError func for writing Twirp errors to http.ResponseWriter #192
Conversation
At last! Thanks for doing this. |
// | ||
// Silently ignoring the error is our least-bad option. It's highly | ||
// likely that the connection is broken and the original 'err' says | ||
// so anyway. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
spenczar
Nov 26, 2019
Member
Ah! You're completely right that this is a very different situation from the generated code. This should most certainly be able to return an error.
It's unfortunate that this would be a breaking change and require a major version bump. This is why public API is hard. Ouch.
This comment has been minimized.
This comment has been minimized.
mfridman
Nov 26, 2019
Author
Contributor
Indeed this could return an error, and probably should within this pkg.
But on the flip-side, it would no longer be a drop-in replacement to the generated version of WriteError
.
In our case we were importing stub packages in various places outside the twirp stack, so it made sense to have it this way.
But it wouldn't be too hard to refactor with the returned error (we'd probably drop it anyways).
Maybe in a v6 we could add a returned error, or in v5 add a new function that returns the underlying error.
This comment has been minimized.
This comment has been minimized.
ofpiyush
Nov 28, 2019
It would technically break the public API, but would not do so in a code-breaking way.
Since this function doesn't return anything, all existing code would look like
twirp.WriteError(resp, err)
This would not break if you started returning errors. i.e. you can get away with adding it in a minor version.
If that feels too close to the edge of the dark side.
v5 add a new function that returns the underlying error.
I do not claim to know how to cleanly fix a public API. Probably something like this work?
- Add another method to return error
- Mark the current one deprecated
- In V6, drop the current method
This comment has been minimized.
This comment has been minimized.
spenczar
Dec 2, 2019
Member
I like this discussion - let's move it to an issue though, since I don't think anybody else is seeing this :) @ofpiyush, can you make an issue?
mfridman commentedNov 1, 2019
Fixes #186 #161
This changeset copies the twirp service implementation of
WriteError
to the coretwitchtv/twirp
package.Note, all mention of "hooks" and underlying use of context has been removed.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.