Skip to content

Conversation

@pujitm
Copy link
Member

@pujitm pujitm commented Jul 21, 2025

prevents log explosion due to large, invalid notifications.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of invalid or corrupted notifications by displaying a warning message instead of causing errors or interruptions.
    • Enhanced robustness in displaying notification timestamps by gracefully handling invalid date formats.
  • Refactor

    • Improved internal date formatting for notifications, ensuring more consistent and user-friendly display.

prevents log explosion due to large, invalid notifications.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 21, 2025

Walkthrough

The NotificationsService was updated to handle invalid notification files more gracefully by catching validation errors, logging warnings, and returning a masked warning notification instead of throwing. Additionally, timestamp formatting was refactored for better separation of concerns and robustness against invalid date inputs.

Changes

File(s) Change Summary
api/src/unraid-api/graph/resolvers/notifications/notifications.service.ts Refactored error handling in loadNotificationFile to mask invalid notifications; split timestamp formatting logic; added formatDatetime helper method.
api/src/unraid-api/graph/resolvers/notifications/loadNotificationsFile.test.ts Added comprehensive unit tests for loadNotificationFile covering validation errors, timestamp handling, and field filtering.
api/src/unraid-api/graph/resolvers/notifications/notifications.service.spec.ts Added detailed file-level comment header describing integration-style tests and test scope; no functional changes.

Estimated code review effort

3 (~40 minutes)

Possibly related PRs

Suggested reviewers

  • mdatelle
  • elibosley

Poem

When notifications go astray,
No longer do we throw away—
A warning logged, a mask applied,
Corrupted data, gently tied.
Dates now parsed with extra care,
Robust and tidy everywhere!
🛎️✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d1103f and 00a6c11.

📒 Files selected for processing (2)
  • api/src/unraid-api/graph/resolvers/notifications/loadNotificationsFile.test.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/notifications/notifications.service.spec.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • api/src/unraid-api/graph/resolvers/notifications/notifications.service.spec.ts
🧰 Additional context used
📓 Path-based instructions (3)
api/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/api-rules.mdc)

api/**/*: Use pnpm as the only package manager
Always run scripts from api/package.json unless specifically requested otherwise

Files:

  • api/src/unraid-api/graph/resolvers/notifications/loadNotificationsFile.test.ts
api/src/unraid-api/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/api-rules.mdc)

Prefer adding new files to the NestJS repository located at api/src/unraid-api/ instead of the legacy code

Files:

  • api/src/unraid-api/graph/resolvers/notifications/loadNotificationsFile.test.ts
api/**/*.{test,spec}.{js,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/api-rules.mdc)

api/**/*.{test,spec}.{js,ts,tsx}: Use Vitest as the test suite; do not use Jest
Prefer not to mock simple dependencies in tests

Files:

  • api/src/unraid-api/graph/resolvers/notifications/loadNotificationsFile.test.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: elibosley
PR: unraid/api#1101
File: api/src/unraid-api/unraid-file-modifier/modifications/patches/default-page-layout.patch:24-27
Timestamp: 2025-01-31T22:01:22.708Z
Learning: The Unraid UI uses a modern notification system with a custom `unraid-toaster` component replacing the legacy jGrowl notifications. The system is backed by a comprehensive GraphQL API with real-time subscription support for notification updates.
Learnt from: pujitm
PR: unraid/api#1075
File: web/components/Notifications/Sidebar.vue:52-57
Timestamp: 2025-01-30T19:56:42.055Z
Learning: Notification links in the Unraid API are validated at creation time on the server side, making additional client-side validation unnecessary when receiving notifications through GraphQL subscriptions.
Learnt from: elibosley
PR: unraid/api#1101
File: api/src/unraid-api/unraid-file-modifier/modifications/patches/default-page-layout.patch:30-54
Timestamp: 2025-01-31T22:01:02.725Z
Learning: The removal of jGrowl notifications from DefaultPageLayout.php is intentional as notifications are now handled on a separate page as part of the architectural design to override existing Unraid pages.
Learnt from: elibosley
PR: unraid/api#1101
File: api/src/unraid-api/unraid-file-modifier/modifications/patches/default-page-layout.patch:6-20
Timestamp: 2025-01-31T22:01:41.842Z
Learning: The default-page-layout.patch is used to remove the old jGrowl notification system from Unraid pages, as notifications are handled by a new system implemented on a different page.
Learnt from: pujitm
PR: unraid/api#967
File: web/components/Notifications/graphql/notification.query.ts:13-13
Timestamp: 2024-11-22T15:47:54.695Z
Learning: The `formattedTimestamp` field in the `Notification` type is already provided via `NotificationsResolver::list`.
Learnt from: pujitm
PR: unraid/api#941
File: web/components/Notifications/Item.vue:0-0
Timestamp: 2024-11-01T17:52:55.311Z
Learning: In the `web/components/Notifications/Item.vue` component, ensure that when delete or archive mutations fail, the notification remains displayed, and an error message is shown below the action buttons to inform the user.
Learnt from: pujitm
PR: unraid/api#1075
File: web/components/Notifications/Sidebar.vue:41-58
Timestamp: 2025-01-31T14:42:06.752Z
Learning: When handling errors in code that uses toast notifications, avoid using toast in the error handler itself since toast functionality might be the source of the error. Use console.error or other reliable logging mechanisms instead.
Learnt from: zackspear
PR: unraid/api#1257
File: plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix/include/ReplaceKey.php:184-184
Timestamp: 2025-03-20T01:58:31.676Z
Learning: Error messages from the key server or KeyInstaller do not contain PII or server details, so they can be safely used in notifications.
Learnt from: pujitm
PR: unraid/api#1352
File: packages/unraid-api-plugin-generator/src/create-plugin.ts:91-112
Timestamp: 2025-04-21T18:27:36.482Z
Learning: For utility functions like file operations in api plugin generators, pujitm prefers minimal error handling rather than verbose try/catch blocks for each operation, as errors will propagate properly to higher level error handlers.
api/src/unraid-api/graph/resolvers/notifications/loadNotificationsFile.test.ts (14)

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Mock external dependencies appropriately in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Test getter dependencies are properly mocked in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Verify proper error handling in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/{components,store,mocks}/**/*.ts : Mock external dependencies and services in tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Verify state changes by updating the store in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Test async operations completely in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/{components,store,mocks}/**/*.ts : Use factory functions for module mocks to avoid hoisting issues

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Do not mock the store being tested in the test file

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Verify state changes after actions in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/mocks/**/*.ts : Frequently used mocks are stored under web/test/mocks

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/{components,store,mocks}/**/*.ts : Remember that vi.mock() calls are hoisted

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/{components,store,mocks}/**/*.ts : Use vi.mock() for module-level mocks

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/{components,store,mocks}/**/*.ts : Reset mocks between tests with vi.clearAllMocks()

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/api-rules.mdc:0-0
Timestamp: 2025-07-21T14:00:06.258Z
Learning: Applies to api/**/*.{test,spec}.{js,ts,tsx} : Prefer not to mock simple dependencies in tests

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Build Web App
  • GitHub Check: Build API
  • GitHub Check: Test API
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (9)
api/src/unraid-api/graph/resolvers/notifications/loadNotificationsFile.test.ts (9)

1-11: Well-structured imports and clear file purpose.

The imports are properly organized and use the correct Vitest framework as specified in the coding guidelines. The absolute import paths follow the established codebase patterns.


14-38: Appropriate minimal mocking strategy.

The mock setup follows the coding guidelines by keeping mocks minimal and only mocking external dependencies that would be complex to test with directly. The factory functions properly avoid hoisting issues.


40-45: Clean test setup with proper isolation.

The test suite setup correctly creates fresh service instances for each test, ensuring proper test isolation.


47-77: Comprehensive validation of the happy path.

This test thoroughly validates successful notification loading with proper enum conversion, timestamp formatting, and field mapping. The mock data is realistic and the assertions are comprehensive.


79-99: Excellent validation of graceful error handling.

This test directly validates the PR's core objective of gracefully handling invalid notifications by returning masked warning notifications instead of throwing errors. This prevents the log explosion mentioned in the PR objectives.


101-123: Good validation of enum fallback behavior.

This test properly validates that invalid enum values fall back to INFO importance without triggering the masked warning notification, which is appropriate behavior distinct from validation errors.


125-144: Consistent validation error handling coverage.

This test provides good additional coverage for validation errors with missing required fields, confirming that the masking behavior is applied consistently across different validation failure scenarios.


146-179: Important validation of data filtering and security.

This test ensures that only known fields are preserved in notifications, preventing unexpected data passthrough which could have security implications. The explicit check for custom field absence is well done.


181-227: Robust timestamp handling validation.

These tests properly validate graceful handling of timestamp issues. The behavior of returning undefined for missing timestamps and preserving the original string for malformed timestamps provides good debugging information while maintaining system stability.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@elibosley
Copy link
Member

Should we add a unit test for this?

@pujitm
Copy link
Member Author

pujitm commented Jul 21, 2025

Should we add a unit test for this?

great call, on it

@github-actions
Copy link
Contributor

This plugin has been deployed to Cloudflare R2 and is available for testing.
Download it at this URL:

https://preview.dl.unraid.net/unraid-api/tag/PR1529/dynamix.unraid.net.plg

@pujitm pujitm merged commit 05056e7 into main Jul 21, 2025
11 checks passed
@pujitm pujitm deleted the fix/notif-logging branch July 21, 2025 19:28
elibosley pushed a commit that referenced this pull request Jul 28, 2025
🤖 I have created a release *beep* *boop*
---


## [4.11.0](v4.10.0...v4.11.0)
(2025-07-28)


### Features

* tailwind v4 ([#1522](#1522))
([2c62e0a](2c62e0a))
* **web:** install and configure nuxt ui
([#1524](#1524))
([407585c](407585c))


### Bug Fixes

* add missing breakpoints
([#1535](#1535))
([f5352e3](f5352e3))
* border color incorrect in tailwind
([#1544](#1544))
([f14b74a](f14b74a))
* **connect:** omit extraneous fields during connect config validation
([#1538](#1538))
([45bd736](45bd736))
* **deps:** pin dependencies
([#1528](#1528))
([a74d935](a74d935))
* **deps:** pin dependency @nuxt/ui to 3.2.0
([#1532](#1532))
([8279531](8279531))
* **deps:** update all non-major dependencies
([#1510](#1510))
([1a8da6d](1a8da6d))
* **deps:** update all non-major dependencies
([#1520](#1520))
([e2fa648](e2fa648))
* inject Tailwind CSS into client entry point
([#1537](#1537))
([86b6c4f](86b6c4f))
* make settings grid responsive
([#1463](#1463))
([9dfdb8d](9dfdb8d))
* **notifications:** gracefully handle & mask invalid notifications
([#1529](#1529))
([05056e7](05056e7))
* truncate log files when they take up more than 5mb of space
([#1530](#1530))
([0a18b38](0a18b38))
* use async for primary file read/writes
([#1531](#1531))
([23b2b88](23b2b88))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
mdatelle pushed a commit that referenced this pull request Jul 30, 2025
🤖 I have created a release *beep* *boop*
---


## [4.11.0](v4.10.0...v4.11.0)
(2025-07-28)


### Features

* tailwind v4 ([#1522](#1522))
([2c62e0a](2c62e0a))
* **web:** install and configure nuxt ui
([#1524](#1524))
([407585c](407585c))


### Bug Fixes

* add missing breakpoints
([#1535](#1535))
([f5352e3](f5352e3))
* border color incorrect in tailwind
([#1544](#1544))
([f14b74a](f14b74a))
* **connect:** omit extraneous fields during connect config validation
([#1538](#1538))
([45bd736](45bd736))
* **deps:** pin dependencies
([#1528](#1528))
([a74d935](a74d935))
* **deps:** pin dependency @nuxt/ui to 3.2.0
([#1532](#1532))
([8279531](8279531))
* **deps:** update all non-major dependencies
([#1510](#1510))
([1a8da6d](1a8da6d))
* **deps:** update all non-major dependencies
([#1520](#1520))
([e2fa648](e2fa648))
* inject Tailwind CSS into client entry point
([#1537](#1537))
([86b6c4f](86b6c4f))
* make settings grid responsive
([#1463](#1463))
([9dfdb8d](9dfdb8d))
* **notifications:** gracefully handle & mask invalid notifications
([#1529](#1529))
([05056e7](05056e7))
* truncate log files when they take up more than 5mb of space
([#1530](#1530))
([0a18b38](0a18b38))
* use async for primary file read/writes
([#1531](#1531))
([23b2b88](23b2b88))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

2 participants