Change-Id: I96ad3f8fdb675bdb249934d92fd5d01d28c7dd6b GitHub-Last-Rev: 969dfc7945b6199ee4b28a04c48e8bbe45f4df7b GitHub-Pull-Request: golang/tools#421 Reviewed-on: https://go-review.googlesource.com/c/tools/+/461075 Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
30 lines
1 KiB
Go
30 lines
1 KiB
Go
// Copyright 2020 The Go MCP SDK Authors. All rights reserved.
|
|
// Use of this source code is governed by an MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
//go:build !go1.16
|
|
// +build !go1.16
|
|
|
|
package jsonrpc2
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
// errClosed is an error with the same string as net.ErrClosed,
|
|
// which was added in Go 1.16.
|
|
var errClosed = errors.New("use of closed network connection")
|
|
|
|
// isErrClosed reports whether err ends in the same string as errClosed.
|
|
func isErrClosed(err error) bool {
|
|
// As of Go 1.16, this could be 'errors.Is(err, net.ErrClosing)', but
|
|
// unfortunately gopls still requires compatibility with
|
|
// (otherwise-unsupported) older Go versions.
|
|
//
|
|
// In the meantime, this error string has not changed on any supported Go
|
|
// version, and is not expected to change in the future.
|
|
// This is not ideal, but since the worst that could happen here is some
|
|
// superfluous logging, it is acceptable.
|
|
return strings.HasSuffix(err.Error(), "use of closed network connection")
|
|
}
|