Must not wrap io.EOF
- Ngôn ngữ chính
- Go
- Star
- 5.5k
- Fork
- 372
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
From the Go docs:
```go
// EOF is the error returned by Read when no more input is available.
// (Read must return EOF itself, not an error wrapping EOF,
// because callers will test for EOF using ==.)
// Functions should return EOF only to signal a graceful end of input.
// If the EOF occurs unexpectedly in a structured data stream,
// the appropriate error is either [ErrUnexpectedEOF] or some other error
// giving more detail.
var EOF = errors.New("EOF")
```
however, `Conn.reader` (and probably others) wrap io.EOF:
```go
func (c *Conn) reader(ctx context.Context) (_ MessageType, _ io.Reader, err error) {
defer errd.Wrap(&err, "failed to get reader")
// Wrap wraps err with fmt.Errorf if err is non nil.
// Intended for use with defer and a named error return.
// Inspired by https://github.com/golang/go/issues/32676.
func Wrap(err *error, f string, v ...any) {
if *err != nil {
*err = fmt.Errorf(f+": %w", append(v, *err)...)
}
}
```
This leads to errors such as https://github.com/hashicorp/yamux/pull/167.
I'd propose special-casing `Wrap` to check for `io.EOF` and would be happy to open a PR.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
Bắt đầu từ errd.Wrap và cách nó được sử dụng trong Conn.reader, sau đó xem lại tài liệu Go io.EOF được trích dẫn trong issue. Tái hiện trường hợp EOF được bọc và kiểm tra các test hiện có của dự án; hoàn thành khi EOF vẫn có thể được so sánh trực tiếp, trong khi các lỗi khác vẫn giữ được ngữ cảnh.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- go
- Lĩnh vực
- networking
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 72/100