Skip to content

fix: keep the bar running when a notification for a script carries a date - #749

Merged
Seb-GRAF merged 3 commits into
mainfrom
fix/748-notification-payload-crash
Nov 17, 2026
Merged

Seb-GRAF merged 3 commits into
mainfrom
fix/748-notification-payload-crash

Conversation

@Seb-GRAF

Copy link
Copy Markdown
Owner

Problem

A script widget subscribed to a distributed notification crashes the bar when the payload holds a date or another value JSON can't hold, such as data. JSONSerialization.data(withJSONObject:) raises an Objective-C exception for those values, which try? doesn't catch. Music's com.apple.Music.playerInfo, which #737 documents for scripts, likely carries a Play Date. Fixes #748.

Changes

  • BarStore.swift: notificationInfo(_:) builds INFO from the payload. It walks nested arrays and dictionaries, turns dates into ISO 8601 strings, and leaves out values that JSONSerialization.isValidJSONObject rejects (data, NaN), so serializing can no longer raise.
  • docs/create-a-widget.md: the INFO row of the variables table says how dates and data appear.

Other JSONSerialization.data(withJSONObject:) calls checked: SceneRenderer.swift:464 writes its own sample crash reports, so no outside data reaches it. Every other JSONSerialization call (Bluetooth.swift, CrashReport.swift, JSONEditor.swift, ThemeLink.swift) only reads JSON, which throws a Swift error instead of raising.

Testing

  • swift build --build-tests -j 2 builds.
  • swift test --skip-build --filter with the new notificationInfoKeepsDatesAndLeavesOutData and the 10 other tests in ScriptEventTests.swift: all 11 pass. The new test feeds a payload with top-level and nested dates, data and nested arrays and dictionaries, and checks the exact INFO JSON.
  • scripts/check.sh --quick passes.
  • Not checked: a real notification from Music. Posting distributed notifications or playing music would have reached the running bar on the machine.

Merging

Any method: one fix: commit.

Merge this before #737, which documents com.apple.Music.playerInfo for scripts. #737's diff applies cleanly on top of this branch. #734 shows the same INFO table row as context, so whichever of the two merges second needs a one-line rebase.

Claude Opus 5.5 via Claude Code (T3 Code)

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between fada873 and 63e1044.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

Notification payloads assigned to INFO are now filtered and serialized through a helper. The helper converts dates to ISO 8601 strings, omits values JSON cannot represent, and returns sorted-key JSON or nil. A test and the widget documentation describe this behavior.

Changes: Notification INFO serialization

Layer / File(s) Summary
Payload conversion and INFO assignment
Sources/StableBar/BarStore.swift, Tests/StableBarTests/ScriptEventTests.swift, docs/create-a-widget.md
notificationInfo converts dates to ISO 8601 strings, filters values JSON cannot represent, and serializes the result with sorted keys. BarStore.display uses the helper for notification payloads. The test checks nested dates and omitted Data values, and the documentation describes these INFO values.

Possibly related issues

  • Issue #303: The documentation now describes date and unsupported-value handling for INFO, but does not provide the requested broader list of notification names and payloads.

Severity of issue fixed: Medium

Merge Risk: Minimal · previous review 8c6f3

This change keeps the bar from crashing when a script notification carries a date or other value JSON cannot encode. No merge-blocking risk was found. The screen-drawing CI step timed out and is worth re-running, but it appears unrelated to this change.

Pre-merge checks: Passed 3

Check name Status Explanation
Description check Passed The description follows the repository template closely. It has a Problem section that explains the crash and links the issue (Fixes #748). The Changes section lists both the BarStore.swift change and…
Linked Issues check Passed Issue #748 requires that the bar keep running when a script notification payload contains a date or a value JSON cannot hold, and that the script receives INFO as JSON with dates kept in a JSON form. …
Out of Scope Changes check Passed All changes in the whole-PR diff (merge base ca6262d to head 8c6f33e) relate to #748. BarStore.swift contains the INFO conversion fix and the notificationInfo helper. The test in ScriptEventTests.swi…
Full details: Description check

Explanation

The description follows the repository template closely. It has a Problem section that explains the crash and links the issue (Fixes #748). The Changes section lists both the BarStore.swift change and the docs change, and explains why each is needed. The Testing section gives the build and test commands with results and states what was not checked, a real Music notification. The Merging section says a single fix: commit with any merge method is fine, and it notes the ordering with #737 and #734. The last line names the model and harness (Claude Opus 5.5 via Claude Code (T3 Code)), which the template requires. Minor gap: the Testing section does not say whether a screens bot image applies, since the change is not visible. That is non-critical.

Full details: Linked Issues check

Explanation

Issue #748 requires that the bar keep running when a script notification payload contains a date or a value JSON cannot hold, and that the script receives INFO as JSON with dates kept in a JSON form. The diff to Sources/StableBar/BarStore.swift at the reviewed head replaces the direct JSONSerialization call in the observer with notificationInfo(_:). That helper converts Date values to ISO 8601 strings with date.formatted(.iso8601), recurses into arrays and dictionaries, and keeps a scalar only when JSONSerialization.isValidJSONObject([value]) is true. Data and NaN values are dropped, so the final JSONSerialization.data(withJSONObject:) call receives only valid JSON objects and cannot raise the Objective-C exception. The helper returns nil if serialization still fails, and the INFO key is then left unset rather than crashing. The new test notificationInfoKeepsDatesAndLeavesOutData, as described in the PR, covers top-level and nested dates, data, and nested containers. The test file was not inspected in this review. The PR does not test a real Music notification. That gap does not change the requirement, which is met by the code path. No other stack members are listed, so no stack objectives apply.

Full details: Out of Scope Changes check

Explanation

All changes in the whole-PR diff (merge base ca6262d to head 8c6f33e) relate to #748. BarStore.swift contains the INFO conversion fix and the notificationInfo helper. The test in ScriptEventTests.swift verifies that helper. The docs/create-a-widget.md change documents the new INFO serialization of dates and omitted values, which follows from the behavior change. No unrelated code, refactoring, or configuration changes appear in the reviewed summary or in the inspected BarStore.swift hunks.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between ca6262d and 8c6f33e.

Files selected for processing: 3

  • Sources/StableBar/BarStore.swift
  • Tests/StableBarTests/ScriptEventTests.swift
  • docs/create-a-widget.md

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Before and after

main at 408bf5e → this pull request at 63e1044 · 188 screens drawn in one CI job · 0 changed

188 unchanged screens

docs/essentials-clock-settings-dark, docs/essentials-clock-settings-light, docs/essentials-dark, docs/essentials-light, docs/essentials-settings-dark, docs/essentials-settings-light, docs/hero-dark, docs/hero-light, docs/popups-dark, docs/popups-light, docs/settings-dark, docs/settings-light, docs/themes-dark, docs/themes-light, scenes/accessibility-guide-dark, scenes/accessibility-guide-light, scenes/app-menu-popup-dark, scenes/app-menu-popup-light, scenes/apple-menu-settings-dark, scenes/apple-menu-settings-light, scenes/bottom-bar-popup-dark, scenes/bottom-bar-popup-light, scenes/chat-popup-dark, scenes/chat-popup-light, scenes/crowded-edit-bar-dark, scenes/crowded-edit-bar-light, scenes/disk-meter-bar-dark, scenes/disk-meter-bar-light, scenes/dock-badges-bar-dark, scenes/dock-badges-bar-light, scenes/edit-bar-wide-group-dark, scenes/edit-bar-wide-group-light, scenes/essentials-clock-popup-dark, scenes/essentials-clock-popup-light, scenes/essentials-disk-popup-dark, scenes/essentials-disk-popup-light, scenes/filled-slider-popup-dark, scenes/filled-slider-popup-light, scenes/group-members-bar-dark, scenes/group-members-bar-light, scenes/gruvbox-bar-dark, scenes/gruvbox-bar-light, scenes/horizontal-list-popup-dark, scenes/horizontal-list-popup-light, scenes/increase-contrast-bar-dark, scenes/increase-contrast-bar-light, scenes/increase-contrast-popup-dark, scenes/increase-contrast-popup-light, scenes/input-source-popup-dark, scenes/input-source-popup-light, scenes/merged-status-bar-dark, scenes/merged-status-bar-light, scenes/notch-flare-bar-dark, scenes/notch-flare-bar-light, scenes/output-device-popup-dark, scenes/output-device-popup-light, scenes/popup-gap-bar-dark, scenes/popup-gap-bar-light, scenes/popup-spacing-bar-dark, scenes/popup-spacing-bar-light, scenes/popup-view-dark, scenes/popup-view-light, scenes/privacy-both-bar-dark, scenes/privacy-both-bar-light, scenes/privacy-hide-when-idle-bar-dark, scenes/privacy-hide-when-idle-bar-light, scenes/privacy-idle-bar-dark, scenes/privacy-idle-bar-light, scenes/privacy-microphone-bar-dark, scenes/privacy-microphone-bar-light, scenes/privacy-settings-dark, scenes/privacy-settings-light, scenes/reduce-transparency-bar-dark, scenes/reduce-transparency-bar-light, scenes/reduce-transparency-glass-bar-dark, scenes/reduce-transparency-glass-bar-light, scenes/ring-bar-dark, scenes/ring-bar-light, scenes/settings-bar-dark, scenes/settings-bar-light, scenes/settings-bar-placement-bottom-dark, scenes/settings-bar-placement-bottom-light, scenes/settings-bar-placement-dark, scenes/settings-bar-placement-light, scenes/settings-crashes-dark, scenes/settings-crashes-light, scenes/settings-disk-widget-dark, scenes/settings-disk-widget-light, scenes/settings-feedback-dark, scenes/settings-feedback-light, scenes/settings-general-dark, scenes/settings-general-light, scenes/settings-general-macos15-dark, scenes/settings-general-macos15-light, scenes/settings-general-move-dark, scenes/settings-general-move-failed-dark, scenes/settings-general-move-failed-light, scenes/settings-general-move-light, scenes/settings-general-move-moving-dark, scenes/settings-general-move-moving-light, scenes/settings-general-move-replace-dark, scenes/settings-general-move-replace-light, scenes/settings-general-setup-open-dark, scenes/settings-general-setup-open-light, scenes/settings-general-spaces-dark, scenes/settings-general-spaces-light, scenes/settings-help-dark, scenes/settings-help-light, scenes/settings-help-starred-dark, scenes/settings-help-starred-light, scenes/settings-narrow-dark, scenes/settings-narrow-light, scenes/settings-package-dark, scenes/settings-package-light, scenes/settings-package-widget-dark, scenes/settings-package-widget-light, scenes/settings-profiles-dark, scenes/settings-profiles-light, scenes/settings-profiles-theme-dark, scenes/settings-profiles-theme-light, scenes/settings-store-dark, scenes/settings-store-light, scenes/settings-theme-dark, scenes/settings-theme-light, scenes/settings-theme-link-dark, scenes/settings-theme-link-light, scenes/settings-tiled-dark, scenes/settings-tiled-light, scenes/settings-tiled-narrowest-dark, scenes/settings-tiled-narrowest-light, scenes/settings-uninstall-dark, scenes/settings-uninstall-failed-dark, scenes/settings-uninstall-failed-light, scenes/settings-uninstall-light, scenes/settings-widget-backgrounds-dark, scenes/settings-widget-backgrounds-light, scenes/settings-workspace-hidden-dark, scenes/settings-workspace-hidden-light, scenes/setup-look-below-menu-bar-dark, scenes/setup-look-dark, scenes/setup-look-no-notch-dark, scenes/setup-move-existing-dark, scenes/setup-move-failed-dark, scenes/setup-move-ready-dark, scenes/setup-move-replace-dark, scenes/setup-omniwm-connection-dark, scenes/setup-permissions-dark, scenes/setup-permissions-spaces-dark, scenes/setup-permissions-spaces-ready-dark, scenes/setup-placement-bottom-dark, scenes/setup-placement-dark, scenes/setup-touches-dark, scenes/setup-touches-macos15-dark, scenes/setup-touches-spaces-dark, scenes/setup-try-dark, scenes/setup-yabai-connection-dark, scenes/slider-end-stop-popup-dark, scenes/slider-end-stop-popup-light, scenes/stablebar-widget-bar-dark, scenes/stablebar-widget-bar-light, scenes/stablebar-widget-settings-dark, scenes/stablebar-widget-settings-light, scenes/starter-bar-dark, scenes/starter-bar-light, scenes/starter-edit-bar-dark, scenes/starter-edit-bar-light, scenes/symbol-variants-bar-dark, scenes/symbol-variants-bar-light, scenes/system-monitor-memory-bar-dark, scenes/system-monitor-memory-bar-light, scenes/system-monitor-shows-settings-dark, scenes/system-monitor-shows-settings-light, scenes/system-monitor-split-warning-bar-dark, scenes/system-monitor-split-warning-bar-light, scenes/update-popup-dark, scenes/update-popup-light, scenes/update-popup-star-github-cli-dark, scenes/update-popup-star-github-cli-light, scenes/update-popup-star-thanks-dark, scenes/update-popup-star-thanks-light, scenes/workspace-badges-bar-dark, scenes/workspace-badges-bar-light, scenes/workspace-focused-window-bar-dark, scenes/workspace-focused-window-bar-light, scenes/workspace-focused-window-padding-bar-dark, scenes/workspace-focused-window-padding-bar-light, scenes/workspace-hidden-apps-bar-dark, scenes/workspace-hidden-apps-bar-light

Visual review: 188 screens, none changed.

@M4n0x

M4n0x commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Seb-GRAF
Seb-GRAF merged commit 62b68f3 into main Nov 17, 2026
29 of 30 checks passed
@Seb-GRAF
Seb-GRAF deleted the fix/748-notification-payload-crash branch November 17, 2026 09:06
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.

A script event whose notification carries a date crashes the bar

2 participants