Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions lib/const/update_checker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart' show kIsWeb, visibleForTesting;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'package:icarus/services/app_error_reporter.dart';
import 'package:icarus/const/settings.dart';
import 'package:icarus/l10n/l10n.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
Expand Down Expand Up @@ -65,11 +66,20 @@ class UpdateChecker {
if (response.statusCode == 200) {
return json.decode(response.body) as Map<String, dynamic>;
} else {
debugPrint('Failed to load version info: ${response.statusCode}');
AppErrorReporter.reportWarning(
'Checking for updates failed: the server answered '
'${response.statusCode}.',
source: 'update_checker',
);
return null;
}
} catch (e) {
debugPrint('Error fetching version info: $e');
} catch (error, stackTrace) {
AppErrorReporter.reportWarning(
'Checking for updates failed.',
source: 'update_checker',
error: error,
stackTrace: stackTrace,
);
return null;
}
}
Expand Down Expand Up @@ -155,15 +165,27 @@ class UpdateChecker {
source: 'windows_store',
message: 'Windows Store checker plugin not available.',
);
} on PlatformException catch (e) {
} on PlatformException catch (e, stackTrace) {
AppErrorReporter.reportWarning(
'Checking the Windows Store for updates failed.',
source: 'update_checker',
error: e,
stackTrace: stackTrace,
);
return UpdateCheckResult(
isSupported: false,
isUpdateAvailable: false,
source: 'windows_store',
errorCode: e.code.isEmpty ? null : int.tryParse(e.code),
message: e.message,
);
} catch (e) {
} catch (e, stackTrace) {
AppErrorReporter.reportWarning(
'Checking the Windows Store for updates failed.',
source: 'update_checker',
error: e,
stackTrace: stackTrace,
);
return UpdateCheckResult(
isSupported: false,
isUpdateAvailable: false,
Expand Down
12 changes: 6 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ Future<void> _initializeDeepLinkHandling() async {
_publishDeepLink(initialLink, source: 'initial');
}
} catch (error, stackTrace) {
developer.log(
'Failed to read initial deep link: $error',
name: 'deep_link',
AppErrorReporter.reportWarning(
'Failed to read the link the app was opened with.',
source: 'deep_link',
error: error,
stackTrace: stackTrace,
);
Expand All @@ -131,9 +131,9 @@ Future<void> _initializeDeepLinkHandling() async {
_deepLinkStreamSub ??= _appLinks.uriLinkStream.listen(
(uri) => _publishDeepLink(uri, source: 'stream'),
onError: (Object error, StackTrace stackTrace) {
developer.log(
'Deep link stream error: $error',
name: 'deep_link',
AppErrorReporter.reportWarning(
'A link sent to the running app failed to arrive.',
source: 'deep_link',
error: error,
stackTrace: stackTrace,
);
Expand Down
72 changes: 39 additions & 33 deletions lib/providers/auth_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -855,11 +855,13 @@ class AuthProvider extends Notifier<AppAuthState> {
}

void _handleSupabaseAuthStreamError(Object error, StackTrace stackTrace) {
log(
'Supabase auth state stream error: $error',
name: 'auth',
error: error,
stackTrace: stackTrace,
AppErrorReporter.reportWarning(
'Supabase auth state stream error.',
source: 'auth',
error: redactAuthDiagnosticText(error),
stackTrace: StackTrace.fromString(
redactAuthDiagnosticText(stackTrace),
),
);

// The token refresh couldn't reach Supabase (offline, or Supabase is
Expand Down Expand Up @@ -907,9 +909,9 @@ class AuthProvider extends Notifier<AppAuthState> {
throw StateError('Discord OAuth browser launch failed');
}
} catch (error, stackTrace) {
log(
'Discord sign-in failed: $error',
name: 'auth',
AppErrorReporter.reportWarning(
'Discord sign-in failed.',
source: 'auth',
error: error,
stackTrace: stackTrace,
);
Expand Down Expand Up @@ -960,9 +962,9 @@ class AuthProvider extends Notifier<AppAuthState> {
state = state.copyWith(isLoading: false);
return null;
} catch (error, stackTrace) {
log(
'Email/password sign-in failed: $error',
name: 'auth',
AppErrorReporter.reportWarning(
'Email/password sign-in failed.',
source: 'auth',
error: error,
stackTrace: stackTrace,
);
Expand Down Expand Up @@ -1081,9 +1083,9 @@ class AuthProvider extends Notifier<AppAuthState> {
ProductMetrics.instance.signUp('signed_in');
return null;
} catch (error, stackTrace) {
log(
'Email/password sign-up failed: $error',
name: 'auth',
AppErrorReporter.reportWarning(
'Email/password sign-up failed.',
source: 'auth',
error: error,
stackTrace: stackTrace,
);
Expand Down Expand Up @@ -1156,9 +1158,9 @@ class AuthProvider extends Notifier<AppAuthState> {
sent: true,
);
} catch (error, stackTrace) {
log(
'Password reset request failed: $error',
name: 'auth',
AppErrorReporter.reportWarning(
'Password reset request failed.',
source: 'auth',
error: error,
stackTrace: stackTrace,
);
Expand Down Expand Up @@ -1198,9 +1200,9 @@ class AuthProvider extends Notifier<AppAuthState> {
ref.read(passwordRecoveryProvider.notifier).finish();
return null;
} catch (error, stackTrace) {
log(
'Setting a new password failed: $error',
name: 'auth',
AppErrorReporter.reportWarning(
'Setting a new password failed.',
source: 'auth',
error: error,
stackTrace: stackTrace,
);
Expand Down Expand Up @@ -1273,9 +1275,9 @@ class AuthProvider extends Notifier<AppAuthState> {
convexAuthStatus: ConvexAuthStatus.signedOut,
);
} catch (error, stackTrace) {
log(
'Sign out failed: $error',
name: 'auth',
AppErrorReporter.reportWarning(
'Sign out failed.',
source: 'auth',
error: error,
stackTrace: stackTrace,
);
Expand Down Expand Up @@ -1512,11 +1514,13 @@ class AuthProvider extends Notifier<AppAuthState> {
error is TimeoutException)) {
_supabaseUnreachable = true;
}
log(
'Supabase refresh failed while fetching Convex token: $error',
name: 'auth',
error: error,
stackTrace: stackTrace,
AppErrorReporter.reportWarning(
'Supabase refresh failed while fetching Convex token.',
source: 'auth',
error: redactAuthDiagnosticText(error),
stackTrace: StackTrace.fromString(
redactAuthDiagnosticText(stackTrace),
),
);
}
}
Expand All @@ -1529,11 +1533,13 @@ class AuthProvider extends Notifier<AppAuthState> {
);
return session.accessToken;
} catch (error, stackTrace) {
log(
'Failed fetching Supabase access token for Convex: $error',
name: 'auth',
error: error,
stackTrace: stackTrace,
AppErrorReporter.reportWarning(
'Failed fetching Supabase access token for Convex.',
source: 'auth',
error: redactAuthDiagnosticText(error),
stackTrace: StackTrace.fromString(
redactAuthDiagnosticText(stackTrace),
),
);
return null;
}
Expand Down
10 changes: 6 additions & 4 deletions lib/providers/collab/cloud_media_upload_queue_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -890,9 +890,9 @@ class CloudMediaUploadQueueNotifier
_logMedia(
'upload.pending_attach ${_describeJob(_getJob(job.jobId))}',
);
} catch (error) {
} catch (error, stackTrace) {
if (await _dropIfStrategyDeleted(job, error)) return;
_reportMediaFailure('upload', error, job);
_reportMediaFailure('upload', error, stackTrace, job);
await _markJobFailed(
job,
'$error',
Expand Down Expand Up @@ -1067,9 +1067,9 @@ class CloudMediaUploadQueueNotifier
_refreshState();
_logMedia('attach.success image=${job.assetPublicId} '
'strategy=${job.strategyPublicId}');
} catch (error) {
} catch (error, stackTrace) {
if (await _dropIfStrategyDeleted(job, error)) return;
_reportMediaFailure('attach', error, job);
_reportMediaFailure('attach', error, stackTrace, job);
final missingIntent = isMissingImageUploadIntentError(error);
await _markJobFailed(
missingIntent
Expand Down Expand Up @@ -1834,12 +1834,14 @@ class CloudMediaUploadQueueNotifier
void _reportMediaFailure(
String stage,
Object error,
StackTrace stackTrace,
CloudMediaUploadJob job,
) {
AppErrorReporter.reportWarning(
redactSyncDiagnosticText('$stage.failed ${_describeJob(job)}'),
source: 'cloud_media.upload_queue',
error: redactSyncDiagnosticText(error),
stackTrace: StackTrace.fromString(redactSyncDiagnosticText(stackTrace)),
);
}

Expand Down
12 changes: 12 additions & 0 deletions lib/providers/collab/remote_library_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ final cloudFolderTreeProvider =
yield const <CloudFolderEntry>[];
return;
}
AppErrorReporter.reportWarning(
'Reading the cloud library folders failed.',
source: 'remote_library:folder_tree',
error: error,
stackTrace: stackTrace,
);
rethrow;
}
});
Expand Down Expand Up @@ -229,6 +235,12 @@ final cloudStrategiesProvider =
yield const <CloudStrategyEntry>[];
return;
}
AppErrorReporter.reportWarning(
'Reading the cloud library strategies failed.',
source: 'remote_library:strategies',
error: error,
stackTrace: stackTrace,
);
rethrow;
}
});
Expand Down
57 changes: 48 additions & 9 deletions lib/providers/collab/remote_strategy_snapshot_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:developer';

import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:icarus/services/app_error_reporter.dart';
import 'package:icarus/collab/cloud_library_copy.dart';
import 'package:icarus/collab/cloud_payload_upgrade.dart';
import 'package:icarus/collab/cloud_strategy_copy_box.dart';
Expand Down Expand Up @@ -453,8 +454,13 @@ class RemoteEditorSnapshotNotifier
if (_keepsCopy &&
isConvexReadUnanswered(error) &&
_activeStrategyPublicId == strategyPublicId) {
log('Remote editor read failed, reading the copy: $error',
name: 'remote_editor', error: error, stackTrace: stackTrace);
_reportWarning(
'Reading the open cloud strategy failed; showing the copy kept '
'on this computer.',
source: 'remote_editor',
error: error,
stackTrace: stackTrace,
);
if (_showCopy(strategyPublicId)) return;
if (state.valueOrNull == null && state.error is! StrategyAccessLost) {
state = AsyncError(
Expand Down Expand Up @@ -722,9 +728,12 @@ class RemoteEditorSnapshotNotifier
/// The copy is a cache: a write that fails is logged and the editor goes
/// on.
void _keep(Future<void> Function() write) {
void report(Object error, StackTrace stackTrace) =>
log('Keeping a cloud answer on this computer failed: $error',
name: 'remote_editor', error: error, stackTrace: stackTrace);
void report(Object error, StackTrace stackTrace) => _reportWarning(
'Keeping a copy of the cloud strategy on this computer failed.',
source: 'remote_editor',
error: error,
stackTrace: stackTrace,
);
try {
unawaited(write().catchError(report));
} catch (error, stackTrace) {
Expand Down Expand Up @@ -819,14 +828,40 @@ class RemoteEditorSnapshotNotifier
return;
}
ref.read(clientUpgradeRequiredProvider.notifier).noteError(error);
log('Remote editor read failed: $error',
name: 'remote_editor', error: error, stackTrace: stackTrace);
_reportWarning(
'Reading the open cloud strategy failed.',
source: 'remote_editor:$source',
error: error,
stackTrace: stackTrace,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
);
// A read that failed for another reason (offline, say) says nothing
// about access already confirmed gone.
if (state.error is StrategyAccessLost) return;
state = AsyncError(error, stackTrace);
}

/// Writes a failed read to the debug report with the share link's code
/// taken out: a viewer reads with it, and a server error can quote the
/// arguments it was sent.
void _reportWarning(
String message, {
required String source,
required Object error,
StackTrace? stackTrace,
}) {
final token = _shareToken;
String redact(Object? text) => token == null || token.isEmpty
? '$text'
: '$text'.replaceAll(token, '<link code>');
AppErrorReporter.reportWarning(
message,
source: source,
error: redact(error),
stackTrace:
stackTrace == null ? null : StackTrace.fromString(redact(stackTrace)),
);
}

void _handleSubscriptionError({
required String source,
required Object error,
Expand All @@ -840,8 +875,12 @@ class RemoteEditorSnapshotNotifier
));
return;
}
log('Remote editor subscription failed: $error',
name: 'remote_editor', error: error, stackTrace: stackTrace);
_reportWarning(
'Watching the open cloud strategy for changes failed.',
source: 'remote_editor:$source',
error: error,
stackTrace: stackTrace,
);
// A read again would be refused again; the sync button says why.
if (ref.read(clientUpgradeRequiredProvider.notifier).noteError(error)) {
return;
Expand Down
Loading
Loading