~emersion/public-inbox

go-maildir: collect all parse errors during Walk v1 PROPOSED

Bence Ferdinandy: 1
 collect all parse errors during Walk

 1 files changed, 8 insertions(+), 5 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/public-inbox/patches/48969/mbox | git am -3
Learn more about email & git

[PATCH go-maildir] collect all parse errors during Walk Export this patch

Collect all the parse errors during Walk and only expicitly fail, when
the callback errs. Return the Joined errors along with the file names.

Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>
---
 maildir.go | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/maildir.go b/maildir.go
index dc3d9d2..d537405 100644
--- a/maildir.go
+++ b/maildir.go
@@ -82,7 +82,6 @@ func (d Dir) Unseen() ([]string, error) {
		} else if err != nil {
			return keys, err
		}

		for _, n := range names {
			if n[0] == '.' {
				continue
@@ -168,6 +167,7 @@ func (d Dir) Walk(fn func(key string, flags []Flag) error) error {
	}
	defer f.Close()

	var errs error
	for {
		names, err := f.Readdirnames(readdirChunk)
		if errors.Is(err, io.EOF) {
@@ -183,21 +183,24 @@ func (d Dir) Walk(fn func(key string, flags []Flag) error) error {

			key, err := parseKey(n)
			if err != nil {
				return err
				errs = errors.Join(errs, fmt.Errorf("%s: %w", n, err))
				continue
			}

			flags, err := parseFlags(n)
			if err != nil {
				return err
				errs = errors.Join(errs, fmt.Errorf("%s: %w", n, err))
				continue
			}

			if err := fn(key, flags); err != nil {
				return err
				errs = errors.Join(errs, fmt.Errorf("%s: %w", n, err))
				return errs
			}
		}
	}

	return nil
	return errs
}

// Keys returns a slice of valid keys to access messages by.
-- 
2.43.0
Hey,