Skip to content

Commit

Permalink
error: Remove the UnmarshalData method and ErrNoData.
Browse files Browse the repository at this point in the history
Now that the data field is exported from the type, this helper method is no
longer carrying its weight.
  • Loading branch information
creachadair committed Sep 12, 2021
1 parent 0bc4d57 commit c677bac
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 21 deletions.
12 changes: 0 additions & 12 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ func (e Error) HasData() bool { return len(e.Data) != 0 }
// ErrCode trivially satisfies the code.ErrCoder interface for an *Error.
func (e Error) ErrCode() code.Code { return e.Code }

// UnmarshalData decodes the error data associated with e into v. It reports
// ErrNoData without modifying v if there was no data message attached to e.
func (e Error) UnmarshalData(v interface{}) error {
if !e.HasData() {
return ErrNoData
}
return json.Unmarshal(e.Data, v)
}

// MarshalJSON implements the json.Marshaler interface for Error values.
func (e Error) MarshalJSON() ([]byte, error) {
return json.Marshal(jerror{C: int32(e.Code), M: e.Message, D: e.Data})
Expand All @@ -50,9 +41,6 @@ func (e *Error) UnmarshalJSON(data []byte) error {
return nil
}

// ErrNoData indicates that there are no data to unmarshal.
var ErrNoData = errors.New("no data to unmarshal")

// errServerStopped is returned by Server.Wait when the server was shut down by
// an explicit call to its Stop method or orderly termination of its channel.
var errServerStopped = errors.New("the server has been stopped")
Expand Down
10 changes: 1 addition & 9 deletions jrpc2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,6 @@ func TestErrorOnly(t *testing.T) {
t.Errorf("ErrorOnly: got %v, want *Error", err)
} else if e.Code != 1 || e.Message != errMessage {
t.Errorf("ErrorOnly: got (%s, %s), want (1, %s)", e.Code, e.Message, errMessage)
} else {
var data json.RawMessage
if err, want := e.UnmarshalData(&data), jrpc2.ErrNoData; err != want {
t.Errorf("UnmarshalData: got %#q, %v, want %v", string(data), err, want)
}
}
})
t.Run("CallExpectingOK", func(t *testing.T) {
Expand Down Expand Up @@ -467,10 +462,7 @@ func TestErrors(t *testing.T) {
if e.Message != errMessage {
t.Errorf("Error message: got %q, want %q", e.Message, errMessage)
}
var data json.RawMessage
if err := e.UnmarshalData(&data); err != nil {
t.Errorf("Unmarshaling error data: %v", err)
} else if s := string(data); s != errData {
if s := string(e.Data); s != errData {
t.Errorf("Error data: got %q, want %q", s, errData)
}
} else {
Expand Down

0 comments on commit c677bac

Please sign in to comment.