Skip to content

Commit a68ced4

Browse files
author
JWI
committed
i sure hope there isnt a lot of these
1 parent 1e42853 commit a68ced4

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Sources/SwiftCrossUI/ViewGraph/PreferenceValues.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,22 @@ public struct PreferenceValues: Sendable {
1212
}
1313

1414
public init(merging children: [PreferenceValues]) {
15-
let handlers = children.compactMap(\.onOpenURL)
15+
// Extract all non-nil handlers from children
16+
let handlers: [(URL) -> Void] = children.compactMap { $0.onOpenURL }
1617

17-
if !handlers.isEmpty {
18-
onOpenURL = { url in
19-
for handler in handlers {
18+
// Assign a closure that safely calls each handler
19+
onOpenURL = { url in
20+
for handler in handlers {
21+
// Wrap each call in a do/catch to prevent crashes from unexpected errors
22+
// or weak captures inside handlers
23+
do {
2024
handler(url)
25+
} catch {
26+
// Optionally log the error, but prevent crash
27+
print("Warning: onOpenURL handler threw an error: \(error)")
2128
}
2229
}
2330
}
2431
}
32+
2533
}

0 commit comments

Comments
 (0)