From a843fd7ff4bd9271722cb52869e8c16dcb727c86 Mon Sep 17 00:00:00 2001 From: jordan Date: Mon, 23 Feb 2026 05:52:58 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20make=20NOTIFY=5FAPI=5FKEY=20optional=20?= =?UTF-8?q?=E2=80=94=20fall=20back=20to=20log-only=20email=20mode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NOTIFY_URL is a global platform credential; NOTIFY_API_KEY is project- scoped and may not be provisioned if notify setup failed or the notifyProvisioner wasn't configured. Previously the service would crash on startup with "invalid configuration: API key is required" when NOTIFY_URL was set but NOTIFY_API_KEY was missing. Now the condition checks both: only initialize the notify client when both NOTIFY_URL and NOTIFY_API_KEY are set. When either is absent, fall back to log-only mode with a warning (instead of os.Exit(1)). This is the correct behavior: email not delivered is survivable, but a service crash on startup breaks the entire application. Co-Authored-By: Claude Sonnet 4.6 --- .../components/service/cmd/server/main.go.tmpl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/adapter/templates/templates/components/service/cmd/server/main.go.tmpl b/internal/adapter/templates/templates/components/service/cmd/server/main.go.tmpl index 1ef61c9..1532773 100644 --- a/internal/adapter/templates/templates/components/service/cmd/server/main.go.tmpl +++ b/internal/adapter/templates/templates/components/service/cmd/server/main.go.tmpl @@ -173,9 +173,11 @@ func main() { } logger.Info("email renderer loaded", "templates", len(emailRenderer.Purposes())) - // Create email sender — notify service in production (NOTIFY_URL set), log-only for dev. + // Create email sender — notify service in production (NOTIFY_URL + NOTIFY_API_KEY set), log-only for dev. + // NOTIFY_URL is a global platform credential; NOTIFY_API_KEY is project-scoped and may not be + // provisioned yet. If either is missing, fall back to log-only mode instead of crashing. var emailSender port.EmailSender - if cfg.NotifyURL != "" { + if cfg.NotifyURL != "" && cfg.NotifyAPIKey != "" { notifyClient, err := notify.NewClient(notify.Config{ URL: cfg.NotifyURL, APIKey: cfg.NotifyAPIKey, @@ -189,7 +191,11 @@ func main() { logger.Info("email sender initialized (notify)", "url", cfg.NotifyURL, "host", cfg.NotifyHost) } else { emailSender = emailadapter.NewLogSender(logger) - logger.Info("email sender initialized (log-only dev mode)") + if cfg.NotifyURL != "" { + logger.Warn("email sender in log-only mode (NOTIFY_API_KEY not set)") + } else { + logger.Info("email sender initialized (log-only dev mode)") + } } // Create services (business logic)