diff --git a/error.go b/error.go index 63f0a73..4b66f16 100644 --- a/error.go +++ b/error.go @@ -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}) @@ -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") diff --git a/jrpc2_test.go b/jrpc2_test.go index c98d80e..5ec87bb 100644 --- a/jrpc2_test.go +++ b/jrpc2_test.go @@ -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) { @@ -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 {