errcheck icon indicating copy to clipboard operation
errcheck copied to clipboard

Check for errors returned from iterators

Open jeromefroe opened this issue 11 months ago • 0 comments

Hi! I was wondering if you thought it would be worthwhile for errcheck to check for unchecked errors returned from iterators? For example, in the following code snippet, the error returned from the iter.Seq2[string, error] is silently elided both times:

package main

import (
	"fmt"
	"iter"
)

func fallibleIter() iter.Seq2[string, error] {
	strs := []string{"a", "b", "c"}
	return func(yield func(string, error) bool) {
		for _, str := range strs {
			if !yield(str, nil) {
				return
			}
		}
	}
}

func main() {
	for s := range fallibleIter() {
		fmt.Println(s)
	}

	for s, _ := range fallibleIter() {
		fmt.Println(s)
	}
}

jeromefroe avatar Jan 27 '25 21:01 jeromefroe