Skip to content

Check for errors returned from iterators #261

@jeromefroe

Description

@jeromefroe

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)
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions