Workspace notifications crash for alerts without monitors #38

Closed
opened 2026-04-05 16:18:44 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @Eliaxie on 3/11/2026

Description

Alerts created without a monitor cause workspace notifications (Slack/Teams) to fail silently.

Error

TypeError: Cannot read properties of null (reading 'id')
    at Service.getValuesBasedOnNotificationFor (WorkspaceNotificationRuleService.ts:2068:26)
    at async Service.getMatchingNotificationRules (WorkspaceNotificationRuleService.ts:2426:9)
    at async Service.getExistingChannelNamesBasedOnEventType (WorkspaceNotificationRuleService.ts:839:7)
    at async Service.sendWorkspaceMarkdownNotification (WorkspaceNotificationRuleService.ts:575:9)
    at async Service.sendWorkspaceNotification (AlertFeedService.ts:127:12)

Root Cause

Regression introduced in commit 76ab3a8cd6 which changed:

-          alert.monitor?.id!.toString() || "",
+          alert.monitor!.id!.toString() || "",

The optional chaining (?.) was removed, causing a crash when alert.monitor is null.

Steps to Reproduce

  1. Create an alert without attaching a monitor (via API or UI)
  2. Have a workspace notification rule configured for Alert events
  3. Observe that no Slack/Teams notification is sent
  4. Check worker logs for the TypeError

Expected Behavior

Alerts without monitors should still trigger workspace notifications, with an empty monitors array in the notification context.

Proposed Fix

Restore optional chaining and handle null gracefully:

[NotificationRuleConditionCheckOn.Monitors]: alert.monitor?.id 
  ? [alert.monitor.id.toString()] 
  : [],
*Originally created by @Eliaxie on 3/11/2026* ## Description Alerts created without a monitor cause workspace notifications (Slack/Teams) to fail silently. ## Error ``` TypeError: Cannot read properties of null (reading 'id') at Service.getValuesBasedOnNotificationFor (WorkspaceNotificationRuleService.ts:2068:26) at async Service.getMatchingNotificationRules (WorkspaceNotificationRuleService.ts:2426:9) at async Service.getExistingChannelNamesBasedOnEventType (WorkspaceNotificationRuleService.ts:839:7) at async Service.sendWorkspaceMarkdownNotification (WorkspaceNotificationRuleService.ts:575:9) at async Service.sendWorkspaceNotification (AlertFeedService.ts:127:12) ``` ## Root Cause Regression introduced in commit 76ab3a8cd69fbe66c9f7190aca7ce45fa7c40b20 which changed: ```diff - alert.monitor?.id!.toString() || "", + alert.monitor!.id!.toString() || "", ``` The optional chaining (`?.`) was removed, causing a crash when `alert.monitor` is `null`. ## Steps to Reproduce 1. Create an alert without attaching a monitor (via API or UI) 2. Have a workspace notification rule configured for Alert events 3. Observe that no Slack/Teams notification is sent 4. Check worker logs for the TypeError ## Expected Behavior Alerts without monitors should still trigger workspace notifications, with an empty monitors array in the notification context. ## Proposed Fix Restore optional chaining and handle null gracefully: ```typescript [NotificationRuleConditionCheckOn.Monitors]: alert.monitor?.id ? [alert.monitor.id.toString()] : [], ```
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/oneuptime#38