Skip to content

Ignore errors in closures passed to specific functions #51

Description

@SOF3

I have a utility function like this:

type Slice[T any] []T

func (slice Slice[T]) TryForEach(message string, fn func(T) error) error {
    for _, item := range slice {
        if err := fn(item); err != nil {
            return errors.Wrap(err, message)
        }
    }
    return nil
}

However, when I call this function:

slice.TryForEach("message", func(value T) error {
    return otherpkg.DoSomething(value)
}

I get an error for not wrapping DoSomething.

TryForEach actually already wraps the error. It would be useful to have an ignore directive like this:

wrapcheck:
  ignoreClosureInArgList:
    - func: "TryForEach"
      param: "fn"

such that the lint is disabled for top-level return statements (and not including nested closures) in closures if the closure is directly passed as the fn parameter for a function matching TryForEach.

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