Skip to content

Commit 101b92d

Browse files
committed
error: move NewErrorf to error.go
1 parent 6a7f746 commit 101b92d

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

error.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
package jsonrpc2
66

7+
import (
8+
"fmt"
9+
)
10+
711
type ErrorCode int64
812

913
const (
@@ -42,3 +46,12 @@ func (e *Error) Error() string {
4246
}
4347
return e.Message
4448
}
49+
50+
// NewErrorf builds a Error struct for the suppied message and code.
51+
// If args is not empty, message and args will be passed to Sprintf.
52+
func NewErrorf(code ErrorCode, format string, args ...interface{}) *Error {
53+
return &Error{
54+
Code: code,
55+
Message: fmt.Sprintf(format, args...),
56+
}
57+
}

jsonrpc2.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,14 @@ type Conn struct {
4343
type Handler func(context.Context, *Conn, *Request)
4444

4545
// Canceler is an option you can pass to NewConn which is invoked for
46-
// cancelled outgoing requests.
46+
// canceled outgoing requests.
4747
// The request will have the ID filled in, which can be used to propagate the
4848
// cancel to the other process if needed.
4949
// It is okay to use the connection to send notifications, but the context will
50-
// be in the cancelled state, so you must do it with the background context
50+
// be in the canceled state, so you must do it with the background context
5151
// instead.
5252
type Canceler func(context.Context, *Conn, *Request)
5353

54-
// NewErrorf builds a Error struct for the suppied message and code.
55-
// If args is not empty, message and args will be passed to Sprintf.
56-
func NewErrorf(code ErrorCode, format string, args ...interface{}) *Error {
57-
return &Error{
58-
Code: code,
59-
Message: fmt.Sprintf(format, args...),
60-
}
61-
}
62-
6354
// NewConn creates a new connection object that reads and writes messages from
6455
// the supplied stream and dispatches incoming messages to the supplied handler.
6556
func NewConn(ctx context.Context, s Stream, options ...interface{}) *Conn {

0 commit comments

Comments
 (0)