diff --git a/internal/attention/notifications.go b/internal/attention/notifications.go index 23a2dd36..4f08e9a4 100644 --- a/internal/attention/notifications.go +++ b/internal/attention/notifications.go @@ -5,6 +5,7 @@ import ( "crypto/sha256" "errors" "fmt" + "log/slog" "path/filepath" "sync" "time" @@ -54,6 +55,9 @@ func (m *MacNotifier) Notify(ctx context.Context, n Notification) error { m.mu.Unlock() if start { // outside the lock: the callback may run synchronously m.Center.Authorize(func(err error) { + if err != nil { + slog.Warn("macOS notification permission refused", "event", "notifications_refused", "err", err.Error()) + } m.mu.Lock() m.authErr = err if err != nil { @@ -109,7 +113,11 @@ func (m *MacNotifier) post(ctx context.Context, n Notification) error { } ctx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() - return m.Center.Add(ctx, nativeNotificationRequest(n)) + if err := m.Center.Add(ctx, nativeNotificationRequest(n)); err != nil { + slog.Warn("macOS notification not delivered", "event", "notification_failed", "err", err.Error()) + return err + } + return nil } func nativeNotificationRequest(n Notification) NativeNotificationRequest { diff --git a/internal/cli/collect.go b/internal/cli/collect.go index 54ac2e14..28920b39 100644 --- a/internal/cli/collect.go +++ b/internal/cli/collect.go @@ -3,6 +3,7 @@ package cli import ( "context" "fmt" + "github.com/labstack/driga/internal/attention" "io" "log/slog" "os" @@ -70,6 +71,14 @@ func (c CollectCmd) Run(g *Globals) error { if err != nil { return err } + if runtime.GOOS == "darwin" { + // Record what macOS reports, so a silent notification problem shows in the log. + if status, err := attention.MacNotificationStatus(); err != nil { + slog.Warn("macOS notifications unavailable", "event", "notifications_unavailable", "err", err.Error()) + } else { + slog.Info("macOS notifications", "event", "notifications_status", "status", status) + } + } ctx, stop := notifyContext(context.Background()) defer stop() if c.CPUProfile != "" {