Skip to content

Support multierr.Every #66

@kdeberk

Description

@kdeberk

Hello,

There seems to be a correctness issue the implementation of multiError.Is. I say "seems" because I cannot find any consensus on what errors.Is(err, ErrIgnorable) should actually be doing when err is a multiError containing both ErrIgnorable and an important error (that you do want to handle).

Perhaps Is should only return true if all contained errors match the target, so instead

func (merr *multiError) Is(target error) bool {
        if len(merr.Errors()) == 0 {
                return false
        }
	for _, err := range merr.Errors() {
		if !errors.Is(err, target) {
			return false
		}
	}
	return true
}

an alternative would be that Is is not implemented at all, and then errors.Is should return false.

Again, I don't know if the golang developers ever specified some semantics for errors.Is, but I think that from both an intuitive and practical sense, errors.Is(err, ErrIgnorable) should return false. Intuitive, because a multiError is not equal to a single error, and practical because if the important error is not represented by a value, e.g. val ErrImportant = errors.New(...), then there is no way to easily ignore only ignorable error without calling Errors() and iterating over the individual errors..

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions