Skip to content

Commit

Permalink
Add Next() function to error collection
Browse files Browse the repository at this point in the history
  • Loading branch information
Lekuruu committed Oct 11, 2024
1 parent 22f8a02 commit 551dc6e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion common/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package common
import "fmt"

type ErrorCollection struct {
errors []error
errors []error
position int
}

func (ec *ErrorCollection) Add(err error) {
Expand All @@ -22,6 +23,18 @@ func (ec *ErrorCollection) Pop(index int) error {
return err
}

func (ec *ErrorCollection) Next() error {
if !ec.HasErrors() {
return nil
}
if ec.position >= len(ec.errors) {
return nil
}
err := ec.errors[ec.position]
ec.position++
return err
}

func (ec *ErrorCollection) Errors() []error {
return ec.errors
}
Expand Down

0 comments on commit 551dc6e

Please sign in to comment.