internal/jsonrpc2_v2: export WireError type

This makes it possible for users of the package to us the optional error
data field in error construction and error handling logic.

Updates golang/go#64882

Change-Id: Iaa554f42ff42a0b7355605ba0b49ac67f623da15
Reviewed-on: https://go-review.googlesource.com/c/tools/+/562575
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Dan Kortschak 2024-02-08 11:38:17 +10:30 • committed by Alan Donovan
commit 2f861619f9

View file

@ -96,17 +96,17 @@ func (msg *Response) marshal(to *wireCombined) {
to.Result = msg.Result
}
func toWireError(err error) *wireError {
func toWireError(err error) *WireError {
if err == nil {
// no error, the response is complete
return nil
}
if err, ok := err.(*wireError); ok {
if err, ok := err.(*WireError); ok {
// already a wire error, just use it
return err
}
result := &wireError{Message: err.Error()}
var wrapped *wireError
result := &WireError{Message: err.Error()}
var wrapped *WireError
if errors.As(err, &wrapped) {
// if we wrapped a wire error, keep the code from the wrapped error
// but the message from the outer error