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:
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user