From a17458ff9b94496e4edbbb58f13bd395f559eb0b Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Thu, 12 Mar 2026 02:24:00 +0100 Subject: [PATCH] fix: handle DBusServiceUnknownException on Linux without NetworkManager --- lib/main.dart | 5 +++ lib/providers/offline_mode_provider.dart | 13 +++--- lib/services/multi_server_manager.dart | 52 +++++++++++++----------- 3 files changed, 39 insertions(+), 31 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 8eb77a4c..b0534e57 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -198,6 +198,11 @@ FutureOr _beforeSend(SentryEvent event, Hint _) { return null; } + // Drop DBusServiceUnknownException from Linux without NetworkManager + if (exceptions != null && exceptions.any((e) => e.type == 'DBusServiceUnknownException')) { + return null; + } + // Scrub Plex tokens and server URLs from exception messages if (exceptions != null) { exceptions = exceptions.map((e) { diff --git a/lib/providers/offline_mode_provider.dart b/lib/providers/offline_mode_provider.dart index fb0096c9..ab66fe6a 100644 --- a/lib/providers/offline_mode_provider.dart +++ b/lib/providers/offline_mode_provider.dart @@ -48,9 +48,9 @@ class OfflineModeProvider extends ChangeNotifier { // Check initial connectivity await _updateConnectionFlags(); - // Monitor connectivity changes — wrapped in try-catch because - // connectivity_plus can throw synchronously on Windows (NetworkManager::StartListen) - try { + // Monitor connectivity changes — runZonedGuarded catches async errors from + // connectivity_plus (e.g. DBusServiceUnknownException on Linux without NetworkManager) + runZonedGuarded(() { _connectivitySubscription = Connectivity().onConnectivityChanged.listen( (results) { final wasOffline = isOffline; @@ -61,14 +61,13 @@ class OfflineModeProvider extends ChangeNotifier { } }, onError: (e) { - // Assume network available on stream error _hasNetworkConnection = true; }, ); - } catch (e) { - // Assume network available if stream activation fails + }, (error, stack) { + // connectivity_plus throws DBusServiceUnknownException on Linux without NetworkManager _hasNetworkConnection = true; - } + }); // Monitor server status from MultiServerManager _serverStatusSubscription = _serverManager.statusStream.listen((statusMap) { diff --git a/lib/services/multi_server_manager.dart b/lib/services/multi_server_manager.dart index 4b79c75d..6a3bab30 100644 --- a/lib/services/multi_server_manager.dart +++ b/lib/services/multi_server_manager.dart @@ -316,33 +316,37 @@ class MultiServerManager { } appLogger.i('Starting network monitoring for all servers'); - final connectivity = Connectivity(); - _connectivitySubscription = connectivity.onConnectivityChanged.listen( - (results) { - final status = results.isNotEmpty ? results.first : ConnectivityResult.none; + runZonedGuarded(() { + final connectivity = Connectivity(); + _connectivitySubscription = connectivity.onConnectivityChanged.listen( + (results) { + final status = results.isNotEmpty ? results.first : ConnectivityResult.none; - if (status == ConnectivityResult.none) { - appLogger.w('Connectivity lost, pausing optimization until network returns'); - return; - } + if (status == ConnectivityResult.none) { + appLogger.w('Connectivity lost, pausing optimization until network returns'); + return; + } - appLogger.d( - 'Connectivity change detected, re-optimizing all servers', - error: { - 'status': status.name, - 'interfaces': results.map((r) => r.name).toList(), - 'serverCount': _servers.length, - }, - ); + appLogger.d( + 'Connectivity change detected, re-optimizing all servers', + error: { + 'status': status.name, + 'interfaces': results.map((r) => r.name).toList(), + 'serverCount': _servers.length, + }, + ); - // Re-optimize all servers and re-probe offline ones - _reoptimizeAllServers(reason: 'connectivity:${status.name}'); - checkServerHealth(); - }, - onError: (error, stackTrace) { - appLogger.w('Connectivity listener error', error: error, stackTrace: stackTrace); - }, - ); + // Re-optimize all servers and re-probe offline ones + _reoptimizeAllServers(reason: 'connectivity:${status.name}'); + checkServerHealth(); + }, + onError: (error, stackTrace) { + appLogger.w('Connectivity listener error', error: error, stackTrace: stackTrace); + }, + ); + }, (error, stack) { + appLogger.w('Connectivity monitoring unavailable', error: error); + }); } /// Stop monitoring network connectivity