feat(mobile): share logs from the startup error screen (#32288)

* fix(mobile): hide server addresses and tokens in shared logs

* feat(mobile): share logs from the startup error screen

* use only the shared logs patterns on the startup error screen

* fix(mobile): stop writing server urls and oauth values to the log

* fix(mobile): redact logs where they are read

* redact the startup error screen share

* fix(mobile): hide server addresses and tokens in shared logs

* fix(mobile): stop writing server urls and oauth values to the log

* fix(mobile): redact logs where they are read

* fix(mobile): redact logs when they are written

* log the startup error and share it as a log row

* fix(mobile): hide ipv6 addresses and name labels after their settings

* comment why the startup error row is only added here

(cherry picked from commit f7fa8a3a2d2c3b0ab59f90fbcc3c230c58a2aede)
This commit is contained in:
Santo Shakil
2026-10-22 05:18:40 +03:00
committed by Codex
parent 59bf69f1d5
commit 814cc14f88
5 changed files with 99 additions and 7 deletions
@@ -0,0 +1,56 @@
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:immich_mobile/data/db/logger/database.dart';
import 'package:immich_mobile/data/db/main/database.dart';
import 'package:immich_mobile/domain/models/log.model.dart';
import 'package:immich_mobile/infrastructure/repositories/log.repository.dart';
import 'package:immich_mobile/services/immich_logger.service.dart';
void main() {
testWidgets('Shares the startup error and the stored logs before the log service starts', (tester) async {
final dir = Directory.systemTemp.createTempSync('immich-logs');
addTearDown(() => dir.delete(recursive: true));
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('plugins.flutter.io/path_provider'),
(_) async => dir.path,
);
late String shared;
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('dev.fluttercommunity.plus/share'),
(call) async {
shared = File(((call.arguments as Map)['paths'] as List).single as String).readAsStringSync();
return 'success';
},
);
await tester.pumpWidget(const SizedBox());
await tester.runAsync(() async {
final logs = DriftLogger.sqlite(await openSqliteConnection(name: 'immich_logs'));
await LogRepository(logs).insertAll([
LogMessage(
message: 'Failed to connect to old.example.net/203.0.113.9:443, uri=https://old.example.net/api',
level: LogLevel.warning,
createdAt: DateTime(2026, 10, 15),
),
]);
await logs.close();
await ImmichLogger.shareLogs(
tester.element(find.byType(SizedBox)),
startupError: 'SqliteException(2067): UNIQUE constraint failed, parameters: 14, someone@example.com',
);
});
expect(
shared.split('\n').first,
endsWith('| SqliteException(2067): UNIQUE constraint failed, parameters: 14, someone@example.com |'),
);
expect(
shared,
contains('| Failed to connect to old.example.net/203.0.113.9:443, uri=https://old.example.net/api |'),
);
});
}