coder / coder/websocket

Must not wrap io.EOF

未关闭 适合新手
#561 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Go
星标
5.5k
派生
372
PR 合并指标
30 天内没有已合并 PR

描述

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.

贡献指南

这个仓库没有索引到贡献指南

调研方向

从 errd.Wrap 及其在 Conn.reader 中的使用开始,然后查看 issue 中引用的 Go io.EOF 文档。复现包装 EOF 的情况并检查项目现有的测试;当 EOF 仍可直接比较,而其他错误保留上下文时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
go
领域
networking
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
冷清
描述清晰度
基本清楚
新手友好度
72/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。