Skip to content

Commit

Permalink
Replace Errorf with explicit construction where practical.
Browse files Browse the repository at this point in the history
  • Loading branch information
creachadair committed Sep 24, 2021
1 parent c257879 commit 6114b77
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion base.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (r *Request) ParamString() string { return string(r.params) }

// ErrInvalidVersion is returned by ParseRequests if one or more of the
// requests in the input has a missing or invalid version marker.
var ErrInvalidVersion = Errorf(code.InvalidRequest, "incorrect version marker")
var ErrInvalidVersion error = &Error{Code: code.InvalidRequest, Message: "incorrect version marker"}

// ParseRequests parses a single request or a batch of requests from JSON.
//
Expand Down
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ func (c *Client) marshalParams(ctx context.Context, method string, params interf
if len(pbits) == 0 || (pbits[0] != '[' && pbits[0] != '{' && !isNull(pbits)) {
// JSON-RPC requires that if parameters are provided at all, they are
// an array or an object.
return nil, Errorf(code.InvalidRequest, "invalid parameters: array or object required")
return nil, &Error{Code: code.InvalidRequest, Message: "invalid parameters: array or object required"}
}
bits, err := c.enctx(ctx, method, pbits)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func (s *Server) checkAndAssign(next jmessages) tasks {
} else if !s.versionOK(req.V) {
t.err = ErrInvalidVersion
} else if req.M == "" {
t.err = Errorf(code.InvalidRequest, "empty method name")
t.err = &Error{Code: code.InvalidRequest, Message: "empty method name"}
} else if s.setContext(t, id) {
t.m = s.assign(t.ctx, req.M)
if t.m == nil {
Expand Down Expand Up @@ -615,7 +615,7 @@ func (s *Server) read(ch receiver) {
} else if derr != nil { // parse failure; report and continue
s.pushError(derr)
} else if len(in) == 0 {
s.pushError(Errorf(code.InvalidRequest, "empty request batch"))
s.pushError(&Error{Code: code.InvalidRequest, Message: "empty request batch"})
} else {
s.log("Received request batch of size %d (qlen=%d)", len(in), s.inq.Len())
s.inq.PushBack(in)
Expand Down

0 comments on commit 6114b77

Please sign in to comment.