Improve email config error to name the missing variable(s)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Harry Culpan 2026-06-30 20:37:39 -04:00
parent 48e7acab83
commit eb930b0794

View file

@ -3,6 +3,7 @@ package email
import ( import (
"fmt" "fmt"
"os" "os"
"strings"
"github.com/emersion/go-imap/client" "github.com/emersion/go-imap/client"
"github.com/joho/godotenv" "github.com/joho/godotenv"
@ -44,8 +45,21 @@ func NewConfigFromEnv() (*Config, error) {
fetchServer = os.Getenv("IMAP_SERVER") fetchServer = os.Getenv("IMAP_SERVER")
sendServer = os.Getenv("SMTP_SERVER") sendServer = os.Getenv("SMTP_SERVER")
if len(username) == 0 || len(password) == 0 || len(fetchServer) == 0 || len(sendServer) == 0 { var missing []string
return nil, fmt.Errorf("missing configuration variables") if len(username) == 0 {
missing = append(missing, "EMAIL_USERNAME")
}
if len(password) == 0 {
missing = append(missing, "EMAIL_PASSWORD")
}
if len(fetchServer) == 0 {
missing = append(missing, "IMAP_SERVER")
}
if len(sendServer) == 0 {
missing = append(missing, "SMTP_SERVER")
}
if len(missing) > 0 {
return nil, fmt.Errorf("missing configuration variables: %s", strings.Join(missing, ", "))
} }
return NewConfig(username, password, fetchServer, sendServer), nil return NewConfig(username, password, fetchServer, sendServer), nil