You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: keep the bar running when a notification for a script carries a date - #749
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.
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: 3
Check name
Status
Explanation
Description check
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
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
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.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, whichtry?doesn't catch. Music'scom.apple.Music.playerInfo, which #737 documents for scripts, likely carries aPlay Date. Fixes #748.Changes
BarStore.swift:notificationInfo(_:)buildsINFOfrom the payload. It walks nested arrays and dictionaries, turns dates into ISO 8601 strings, and leaves out values thatJSONSerialization.isValidJSONObjectrejects (data, NaN), so serializing can no longer raise.docs/create-a-widget.md: theINFOrow of the variables table says how dates and data appear.Other
JSONSerialization.data(withJSONObject:)calls checked:SceneRenderer.swift:464writes its own sample crash reports, so no outside data reaches it. Every otherJSONSerializationcall (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 2builds.swift test --skip-build --filterwith the newnotificationInfoKeepsDatesAndLeavesOutDataand the 10 other tests inScriptEventTests.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 exactINFOJSON.scripts/check.sh --quickpasses.Merging
Any method: one
fix:commit.Merge this before #737, which documents
com.apple.Music.playerInfofor scripts. #737's diff applies cleanly on top of this branch. #734 shows the sameINFOtable row as context, so whichever of the two merges second needs a one-line rebase.Claude Opus 5.5 via Claude Code (T3 Code)