Fix nil pointer panic when notifier Send returns nil result

Guard against nil result before accessing result.Error in processNotification,
and add NtfyNotifier.Validate override so DefaultTopic is considered before
rejecting notifications with zero recipients.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-05 01:06:27 -07:00
parent c04db89633
commit a35b3e6283
2 changed files with 18 additions and 2 deletions
+14
View File
@@ -181,6 +181,20 @@ func createNtfyHTTPClient(config *NtfyConfig) (*http.Client, error) {
}, nil
}
// Validate overrides BaseNotifier.Validate to allow 0 recipients when a DefaultTopic is configured.
func (n *NtfyNotifier) Validate(notification *domain.Notification) error {
if notification == nil {
return fmt.Errorf("notification is nil")
}
if notification.Type != domain.TypeNtfy {
return fmt.Errorf("notification type mismatch: expected %s, got %s", domain.TypeNtfy, notification.Type)
}
if len(notification.Recipients) == 0 && n.config.DefaultTopic == "" {
return fmt.Errorf("notification has no recipients and no default topic is configured")
}
return nil
}
// Send sends a notification via ntfy
func (n *NtfyNotifier) Send(ctx context.Context, notification *domain.Notification) (*domain.NotificationResult, error) {
if err := ValidateContext(ctx); err != nil {
+4 -2
View File
@@ -243,9 +243,11 @@ func (s *NotificationService) processNotification(ctx context.Context, msg *doma
// Send the notification
result, err := notifier.Send(ctx, notification)
if err != nil || !result.Success {
if err != nil || result == nil || !result.Success {
notification.RetryCount++
notification.LastError = result.Error
if result != nil {
notification.LastError = result.Error
}
if err != nil {
notification.LastError = err.Error()
}