Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 7, 2026

Summary

Fixes #15281

Notification system crashes with TypeError: Cannot read properties of undefined (reading 'asCookie') when marking notifications as read/unread if the preference property is malformed (e.g., string instead of { key, value } object).

Occurred changes and/or fixed issues

Added defensive validation in shell/store/notifications.ts:

  • isValidPreference() type guard validates preference structure before use
  • markRead, markUnread, markAllRead actions now validate preferences and log errors instead of crashing
  • Malformed preferences are skipped gracefully; valid preferences continue to work

Technical notes summary

The crash occurred because prefs/set expects { key, value } format. When preference is malformed:

  1. key becomes undefined
  2. definition lookup in prefs store fails (returns undefined)
  3. Accessing definition.asCookie throws TypeError

Validation checks:

function isValidPreference(preference: any): preference is NotificationPreference {
  return preference !== null &&
    preference !== undefined &&
    typeof preference === 'object' &&
    !Array.isArray(preference) &&
    typeof preference.key === 'string' &&
    typeof preference.value === 'string' &&
    (preference.unsetValue === undefined || typeof preference.unsetValue === 'string');
}

Protects against: strings, arrays, nulls, objects with missing/wrong-type properties.

Areas or cases that should be tested

  • Mark notification as read/unread with valid preference → works normally
  • Mark notification as read/unread with malformed preference → no crash, error logged to console
  • Mark all as read with mix of valid/invalid preferences → valid ones processed, invalid ones skipped
  • Check console for descriptive error messages when invalid preferences encountered

Areas which could experience regressions

  • Notification center read/unread toggle functionality
  • Mark all notifications as read functionality
  • User preference storage/retrieval for notifications
  • Dynamic content notifications (announcements, release notes, support notices)

Screenshot/Video

Error before fix:
image

After fix: Application continues running, error logged to console for debugging.

Checklist

  • The PR is linked to an issue and the linked issue has a Milestone, or no issue is needed
  • The PR has a Milestone
  • The PR template has been filled out
  • The PR has been self reviewed
  • The PR has a reviewer assigned
  • The PR has automated tests or clear instructions for manual tests and the linked issue has appropriate QA labels, or tests are not needed
  • The PR has reviewed with UX and tested in light and dark mode, or there are no UX changes
  • The PR has been reviewed in terms of Accessibility
  • The PR has considered, and if applicable tested with, the three Global Roles Admin, Standard User and User Base

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • download.cypress.io
    • Triggering command: /usr/local/bin/node /usr/local/bin/node index.js --exec install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Prevent Notifications to break if malformed or wrong data on "mark as read"</issue_title>
<issue_description># Description

In an accident related to a first use case of notifications, it appears that malformed or wrong data can break the application.
In this case it seems break if cookies are missing and data is not existing when flagging read the notifications.

Optionally: Create a type for notification data

Image</issue_description>

<agent_instructions>Ensure the fixes comment in the PR references issue 15281</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@richard-cox Just writing notes
  • notification preference property was set to a string instead of { key, value } object
  • pref store set action tried to find a preference (definition) with key undefined --> definition undefined --> definition.asCookie throws exception</comment_new>

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 6 commits January 7, 2026 14:27
… crashes

- Added isValidPreference helper to validate preference structure
- Updated markRead, markUnread, and markAllRead actions with defensive checks
- Added comprehensive tests for malformed preference handling
- Gracefully log errors instead of crashing when preference is malformed

Co-authored-by: nwmac <[email protected]>
- Added constant for error message to improve maintainability
- Enhanced validation to reject arrays as preferences
- Improved JSDoc documentation for validation function
- Added test for array validation case

Co-authored-by: nwmac <[email protected]>
- Make null and undefined checks explicit for better code readability

Co-authored-by: nwmac <[email protected]>
- Use explicit null and undefined checks to satisfy linter
- Maintain clear validation flow while avoiding redundant checks

Co-authored-by: nwmac <[email protected]>
- Validate that unsetValue is a string if present
- Add test case for invalid unsetValue type
- Ensure complete type safety for NotificationPreference interface

Co-authored-by: nwmac <[email protected]>
Copilot AI changed the title [WIP] Prevent notifications from breaking due to malformed data Prevent notifications from crashing on malformed preference data Jan 7, 2026
Copilot AI requested a review from nwmac January 7, 2026 14:44
@nwmac nwmac closed this Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent Notifications to break if malformed or wrong data on "mark as read"

2 participants