diff --git a/packages/sqlite_async/CHANGELOG.md b/packages/sqlite_async/CHANGELOG.md index 9d5802d..4737282 100644 --- a/packages/sqlite_async/CHANGELOG.md +++ b/packages/sqlite_async/CHANGELOG.md @@ -1,3 +1,11 @@ +## 0.14.2-wip + +- Web: fix uncaught error from `BroadcastUpdates` when a peer publishes a + message that does not deserialise into an `UpdateNotification`. The bare + `.cast()` after `.where()` is now typed explicitly, and a defensive + `onError` handler is attached to the broadcast subscription so malformed + peer payloads degrade silently instead of crashing the host application. + ## 0.14.1 - Fix update notifications sometimes firing before a write has completed. diff --git a/packages/sqlite_async/lib/src/web/database/async_web_database.dart b/packages/sqlite_async/lib/src/web/database/async_web_database.dart index 6084c66..9ca6bff 100644 --- a/packages/sqlite_async/lib/src/web/database/async_web_database.dart +++ b/packages/sqlite_async/lib/src/web/database/async_web_database.dart @@ -70,6 +70,12 @@ final class AsyncWebDatabaseImpl extends SqliteDatabaseImpl _broadcastUpdatesSubscription = broadcastUpdates.updates.listen((updates) { updatesController.add(updates); + }, onError: (Object error, StackTrace stackTrace) { + // Cross-tab BroadcastChannel may deliver payloads that do not + // deserialise into an UpdateNotification (legacy storage mode, + // malformed peer messages, SharedWorker fallback). Drop them + // rather than crashing the host application via an uncaught + // error on the root zone. }); } } diff --git a/packages/sqlite_async/lib/src/web/database/broadcast_updates.dart b/packages/sqlite_async/lib/src/web/database/broadcast_updates.dart index 5514e74..9ece628 100644 --- a/packages/sqlite_async/lib/src/web/database/broadcast_updates.dart +++ b/packages/sqlite_async/lib/src/web/database/broadcast_updates.dart @@ -25,7 +25,7 @@ class BroadcastUpdates { } }) .where((e) => e != null) - .cast(); + .cast(); } void send(UpdateNotification notification) { diff --git a/packages/sqlite_async/pubspec.yaml b/packages/sqlite_async/pubspec.yaml index 2a6e2b9..c4e2a32 100644 --- a/packages/sqlite_async/pubspec.yaml +++ b/packages/sqlite_async/pubspec.yaml @@ -1,6 +1,6 @@ name: sqlite_async description: High-performance asynchronous interface for SQLite on Dart and Flutter. -version: 0.14.1 +version: 0.14.2-wip resolution: workspace repository: https://github.com/powersync-ja/sqlite_async.dart environment: