about summary refs log tree commit diff stats
path: root/worker/maildir/worker.go
diff options
context:
space:
mode:
authorTero Koskinen <tero.koskinen@iki.fi>2020-07-25 11:11:13 +0300
committerReto Brunner <reto@labrat.space>2020-07-27 18:26:57 +0200
commitf81cc2803cca4a5213a9d4514ddae8417c23f8ee (patch)
tree6b3c3c2264b267106bd922ee9734c248cc933934 /worker/maildir/worker.go
parentc574a838fa89bf46bf7188442f400b206b04df95 (diff)
downloadaerc-f81cc2803cca4a5213a9d4514ddae8417c23f8ee.tar.gz
maildir: Provide nicer error message on invalid url
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.
Diffstat (limited to 'worker/maildir/worker.go')
-rw-r--r--worker/maildir/worker.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go
index ce548ff..d1ff3c2 100644
--- a/worker/maildir/worker.go
+++ b/worker/maildir/worker.go
@@ -1,6 +1,7 @@
 package maildir
 
 import (
+	"errors"
 	"fmt"
 	"io"
 	"net/url"
@@ -221,7 +222,15 @@ func (w *Worker) handleConfigure(msg *types.Configure) error {
 		}
 		dir = filepath.Join(home, u.Path)
 	}
-	w.c = NewContainer(dir, w.worker.Logger)
+	if len(dir) == 0 {
+		return fmt.Errorf("could not resolve maildir from URL '%s'", msg.Config.Source)
+	}
+	c, err := NewContainer(dir, w.worker.Logger)
+	if err != nil {
+		w.worker.Logger.Printf("could not configure maildir: %s", dir)
+		return err
+	}
+	w.c = c
 	w.worker.Logger.Printf("configured base maildir: %s", dir)
 	return nil
 }
@@ -231,6 +240,12 @@ func (w *Worker) handleConnect(msg *types.Connect) error {
 }
 
 func (w *Worker) handleListDirectories(msg *types.ListDirectories) error {
+	// TODO If handleConfigure has returned error, w.c is nil.
+	// It could be better if we skip directory listing completely
+	// when configure fails.
+	if w.c == nil {
+		return errors.New("Incorrect maildir directory")
+	}
 	dirs, err := w.c.ListFolders()
 	if err != nil {
 		w.worker.Logger.Printf("error listing directories: %v", err)