Must not wrap io.EOF
- Langage dominant
- Go
- Étoiles
- 5.5k
- Forks
- 372
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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.
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Start at errd.Wrap and its use in Conn.reader, then review the Go io.EOF documentation cited in the issue. Reproduce the wrapped-EOF case and check the project's existing tests; done means EOF remains directly comparable while other errors retain context.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- go
- Domaine
- networking
- Type d'issue
- Bug
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- Calme
- Clarté
- Plutôt claire
- Accessibilité débutants
- 72/100