Skip to content

Commit e1a6261

Browse files
kortschakadonovan
authored andcommitted
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 <[email protected]> Reviewed-by: Than McIntosh <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 1b39a8b commit e1a6261

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

internal/jsonrpc2_v2/messages.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,17 @@ func (msg *Response) marshal(to *wireCombined) {
9696
to.Result = msg.Result
9797
}
9898

99-
func toWireError(err error) *wireError {
99+
func toWireError(err error) *WireError {
100100
if err == nil {
101101
// no error, the response is complete
102102
return nil
103103
}
104-
if err, ok := err.(*wireError); ok {
104+
if err, ok := err.(*WireError); ok {
105105
// already a wire error, just use it
106106
return err
107107
}
108-
result := &wireError{Message: err.Error()}
109-
var wrapped *wireError
108+
result := &WireError{Message: err.Error()}
109+
var wrapped *WireError
110110
if errors.As(err, &wrapped) {
111111
// if we wrapped a wire error, keep the code from the wrapped error
112112
// but the message from the outer error

internal/jsonrpc2_v2/wire.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ type wireCombined struct {
4949
Method string `json:"method,omitempty"`
5050
Params json.RawMessage `json:"params,omitempty"`
5151
Result json.RawMessage `json:"result,omitempty"`
52-
Error *wireError `json:"error,omitempty"`
52+
Error *WireError `json:"error,omitempty"`
5353
}
5454

55-
// wireError represents a structured error in a Response.
56-
type wireError struct {
55+
// WireError represents a structured error in a Response.
56+
type WireError struct {
5757
// Code is an error code indicating the type of failure.
5858
Code int64 `json:"code"`
5959
// Message is a short description of the error.
@@ -67,18 +67,18 @@ type wireError struct {
6767
// only be used to build errors for application specific codes as allowed by the
6868
// specification.
6969
func NewError(code int64, message string) error {
70-
return &wireError{
70+
return &WireError{
7171
Code: code,
7272
Message: message,
7373
}
7474
}
7575

76-
func (err *wireError) Error() string {
76+
func (err *WireError) Error() string {
7777
return err.Message
7878
}
7979

80-
func (err *wireError) Is(other error) bool {
81-
w, ok := other.(*wireError)
80+
func (err *WireError) Is(other error) bool {
81+
w, ok := other.(*WireError)
8282
if !ok {
8383
return false
8484
}

0 commit comments

Comments
 (0)