I added the error checking in v3.
My initial assumption was that fstat() shouldn't fail if we have
successfully opened the directory. But now, after checking the manual
pages, I noticed at least on OpenBSD fstat() can return EIO if there
is a file system reading error during fstat() call.
If accounts.conf contains an invalid maildir url, return a nice
error instead of panicking.
Log a couple of different error cases to provide extra
information about the error to the user.
---
worker/maildir/container.go | 18 +++++++++++++++---worker/maildir/worker.go | 17 ++++++++++++++++-
2 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/worker/maildir/container.go b/worker/maildir/container.go
index cd9a447..fd46fd8 100644
--- a/worker/maildir/container.go+++ b/worker/maildir/container.go
@@ -21,15 +21,27 @@ type Container struct {
}
// NewContainer creates a new container at the specified directory
-// TODO: return an error if the provided directory is not accessible-func NewContainer(dir string, l *log.Logger) *Container {- return &Container{dir: dir, uids: uidstore.NewStore(), log: l}+func NewContainer(dir string, l *log.Logger) (*Container, error) {+ f, err := os.Open(dir)+ if err != nil {+ return nil, err+ }+ s, _ := f.Stat()
Why are you ignoring the error instead of returning it?
If the error is non nil, chances are that s is the zero valued struct, which
isn't overly useful but you still try to call methods on it later.