fix(startup): report and repair a failed launch instead of showing "Error"
Since 2.10.0 the whole app sits behind one all-or-nothing initialization gate, and that gate discarded the only evidence of its own failure. It caught the error, logged nothing but `error.runtimeType`, rendered an icon plus the word "Error" plus Retry, and never reported the error because catching it kept the crash reporter from ever seeing it. There is no log file on any platform, the buffer is in memory only, a double-clicked Windows release build has no console, and the log viewer lives in Settings, behind the gate that just failed. #1732 is the result: a Windows 11 user whose app will not boot and who cannot produce a single byte of diagnostic detail. The gate now names its phases. Each step is wrapped so a throw carries the phase it came from, replacing a `Future.wait` that discarded every error but the first and could not attribute it to any of four concurrent steps. The failure screen renders the phase, the exception type, the message and an expandable stack, plus copy and upload actions that reuse the existing log-relay flow. The record is persisted next to the database so the next successful launch can surface it in Settings > Logs, and it is reported to the crash reporter explicitly. Only preferences and the database still gate the launch. Window chrome, locale, crash-reporting init, TV/performance detection, the image-cache budget and download storage are best-effort and time-bounded, so a stalled platform thread degrades instead of holding the splash forever. Sentry no longer receives the startup work as its `appRunner`: that made a startup failure indistinguishable from a Sentry failure, and the guard would then have re-run migrations and the database open a second time. The two remaining fatal steps become recoverable. Preference reads tolerate a value whose stored type no longer matches, dropping the key and defaulting instead of failing the boot. A store that cannot be parsed is detected before either desktop plugin backend can memoise it, which is what makes an in-process repair possible at all. Repair is never automatic: it states what it will cost, salvages the credential-vault key and every tracker and Seerr session it can validate out of the damaged bytes, reseeds them, and moves the original aside rather than deleting it. Servers and profiles survive a salvaged key because their tokens are ciphertext in the database; tracker and Seerr sessions are plaintext preference entries, so the copy says they may still need reconnecting. Nothing derived from the store reaches a diagnostic. `FormatException` prints an excerpt of whatever it failed to parse, and during startup that document holds the vault key, refresh tokens and session cookies while the redaction manager still has nothing registered, so the wrapper keeps only the cause's type and offset and the record is an allowlist of already-redacted fields. The quarantined copy is labelled as containing credentials, is never offered for upload, and can be deleted from the dialog. Also self-heals orphaned WAL/SHM sidecars on desktop rather than only tvOS, makes every `createTable` migration step idempotent, keeps MSVC link by-products out of the Windows bundle, and asserts bundle contents in CI. Refs #1732
This commit is contained in:
@@ -85,9 +85,10 @@ class AppDatabase extends _$AppDatabase {
|
||||
static final Object _durabilityZoneKey = Object();
|
||||
static final SerialFutureQueue _tvosRecoveryQueue = SerialFutureQueue();
|
||||
|
||||
/// Resolves and opens the production database, eagerly completing Drift
|
||||
/// setup and migrations on non-tvOS before returning. tvOS recovery retains
|
||||
/// ownership of database access ordering.
|
||||
/// Resolves and opens the production database, removing orphaned WAL/SHM
|
||||
/// sidecars when the main database is absent (#1732), then eagerly completing
|
||||
/// Drift setup and migrations on non-tvOS. tvOS recovery retains ownership
|
||||
/// of database access ordering.
|
||||
static Future<AppDatabaseBootstrap> open({
|
||||
bool isTvos = const bool.fromEnvironment('TVOS_BUILD'),
|
||||
File? databaseFile,
|
||||
@@ -105,7 +106,7 @@ class AppDatabase extends _$AppDatabase {
|
||||
}
|
||||
|
||||
final databaseExisted = await file.exists();
|
||||
if (isTvos && !databaseExisted) {
|
||||
if (!databaseExisted) {
|
||||
await _removeOrphanedDatabaseSidecars(file);
|
||||
}
|
||||
|
||||
@@ -379,7 +380,7 @@ class AppDatabase extends _$AppDatabase {
|
||||
onUpgrade: (Migrator m, int from, int to) async {
|
||||
if (from < 7) {
|
||||
appLogger.i('Adding OfflineWatchProgress table (v7 migration)');
|
||||
await m.createTable(offlineWatchProgress);
|
||||
await _ignoreAlreadyExists('OfflineWatchProgress table', () => m.createTable(offlineWatchProgress));
|
||||
}
|
||||
if (from < 8) {
|
||||
appLogger.i('Adding bgTaskId column to DownloadedMedia (v8 migration)');
|
||||
@@ -397,7 +398,7 @@ class AppDatabase extends _$AppDatabase {
|
||||
}
|
||||
if (from < 10) {
|
||||
appLogger.i('Adding SyncRules table (v10 migration)');
|
||||
await m.createTable(syncRules);
|
||||
await _ignoreAlreadyExists('SyncRules table', () => m.createTable(syncRules));
|
||||
}
|
||||
if (from < 11) {
|
||||
appLogger.i('Adding enabled column to SyncRules (v11 migration)');
|
||||
@@ -427,13 +428,13 @@ class AppDatabase extends _$AppDatabase {
|
||||
'Adding Connections, Profiles, ProfileConnections, DownloadOwners + scope/profile columns (v14 migration)',
|
||||
);
|
||||
|
||||
await m.createTable(connections);
|
||||
await _ignoreAlreadyExists('Connections table', () => m.createTable(connections));
|
||||
await _ignoreAlreadyExists('Index idx_connections_kind', () => m.create(idxConnectionsKind));
|
||||
|
||||
await m.createTable(profiles);
|
||||
await _ignoreAlreadyExists('Profiles table', () => m.createTable(profiles));
|
||||
await _ignoreAlreadyExists('Index idx_profiles_kind', () => m.create(idxProfilesKind));
|
||||
|
||||
await m.createTable(profileConnections);
|
||||
await _ignoreAlreadyExists('ProfileConnections table', () => m.createTable(profileConnections));
|
||||
await _ignoreAlreadyExists(
|
||||
'Index idx_profile_connections_connection_id',
|
||||
() => m.create(idxProfileConnectionsConnectionId),
|
||||
@@ -1292,10 +1293,17 @@ Future<File> _resolveProductionDatabaseFile() async {
|
||||
return File(p.join(dbFolder.path, 'plezy_downloads.db'));
|
||||
}
|
||||
|
||||
/// Best-effort removal for sidecars left without a main database after an
|
||||
/// interrupted write. This runs on every platform but only when the caller has
|
||||
/// confirmed the main database is absent (#1732).
|
||||
Future<void> _removeOrphanedDatabaseSidecars(File databaseFile) async {
|
||||
for (final suffix in const ['-wal', '-shm']) {
|
||||
final sidecar = File('${databaseFile.path}$suffix');
|
||||
if (await sidecar.exists()) await sidecar.delete();
|
||||
try {
|
||||
if (await sidecar.exists()) await sidecar.delete();
|
||||
} on FileSystemException catch (error, stackTrace) {
|
||||
appLogger.w('Unable to remove orphaned database sidecar ${sidecar.path}', error: error, stackTrace: stackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user