internal/jsonrpc2*: remove usage of golang.org/x/xerrors
As of golang/go#50827, gopls no longer needs to build at Go 1.12. This was the only reason to continue using xerrors in the jsonrpc2 libraries. Remove this usage as a step toward eliminating the xerrors dependency from x/tools. For golang/go#52442 Change-Id: I1a0a1bbf57e6606c66b99b27439adf6f65c26a60 Reviewed-on: https://go-review.googlesource.com/c/tools/+/401155 Run-TryBot: Robert Findley <rfindley@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
bc1b54354a
commit
bdd1f89abd
1 changed files with 35 additions and 40 deletions
|
|
@ -12,8 +12,6 @@ import (
|
|||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
errors "golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
// Reader abstracts the transport mechanics from the JSON RPC protocol.
|
||||
|
|
@ -87,7 +85,7 @@ func (w *rawWriter) Write(ctx context.Context, msg Message) (int64, error) {
|
|||
}
|
||||
data, err := EncodeMessage(msg)
|
||||
if err != nil {
|
||||
return 0, errors.Errorf("marshaling message: %v", err)
|
||||
return 0, fmt.Errorf("marshaling message: %v", err)
|
||||
}
|
||||
n, err := w.out.Write(data)
|
||||
return int64(n), err
|
||||
|
|
@ -122,7 +120,7 @@ func (r *headerReader) Read(ctx context.Context) (Message, int64, error) {
|
|||
line, err := r.in.ReadString('\n')
|
||||
total += int64(len(line))
|
||||
if err != nil {
|
||||
return nil, total, errors.Errorf("failed reading header line: %w", err)
|
||||
return nil, total, fmt.Errorf("failed reading header line: %w", err)
|
||||
}
|
||||
line = strings.TrimSpace(line)
|
||||
// check we have a header line
|
||||
|
|
@ -131,23 +129,23 @@ func (r *headerReader) Read(ctx context.Context) (Message, int64, error) {
|
|||
}
|
||||
colon := strings.IndexRune(line, ':')
|
||||
if colon < 0 {
|
||||
return nil, total, errors.Errorf("invalid header line %q", line)
|
||||
return nil, total, fmt.Errorf("invalid header line %q", line)
|
||||
}
|
||||
name, value := line[:colon], strings.TrimSpace(line[colon+1:])
|
||||
switch name {
|
||||
case "Content-Length":
|
||||
if length, err = strconv.ParseInt(value, 10, 32); err != nil {
|
||||
return nil, total, errors.Errorf("failed parsing Content-Length: %v", value)
|
||||
return nil, total, fmt.Errorf("failed parsing Content-Length: %v", value)
|
||||
}
|
||||
if length <= 0 {
|
||||
return nil, total, errors.Errorf("invalid Content-Length: %v", length)
|
||||
return nil, total, fmt.Errorf("invalid Content-Length: %v", length)
|
||||
}
|
||||
default:
|
||||
// ignoring unknown headers
|
||||
}
|
||||
}
|
||||
if length == 0 {
|
||||
return nil, total, errors.Errorf("missing Content-Length header")
|
||||
return nil, total, fmt.Errorf("missing Content-Length header")
|
||||
}
|
||||
data := make([]byte, length)
|
||||
n, err := io.ReadFull(r.in, data)
|
||||
|
|
@ -167,7 +165,7 @@ func (w *headerWriter) Write(ctx context.Context, msg Message) (int64, error) {
|
|||
}
|
||||
data, err := EncodeMessage(msg)
|
||||
if err != nil {
|
||||
return 0, errors.Errorf("marshaling message: %v", err)
|
||||
return 0, fmt.Errorf("marshaling message: %v", err)
|
||||
}
|
||||
n, err := fmt.Fprintf(w.out, "Content-Length: %v\r\n\r\n", len(data))
|
||||
total := int64(n)
|
||||
|
|
|
|||
Loading…
Reference in a new issue