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
58 lines
2.2 KiB
Dart
58 lines
2.2 KiB
Dart
import 'dart:convert';
|
||
|
||
import '../utils/media_server_http_client.dart';
|
||
|
||
/// Relay endpoint that returns a short, quotable Log ID.
|
||
const String logUploadEndpoint = 'https://ice.plezy.app/logs';
|
||
|
||
/// Relay `/logs` accepts 1 MiB. The in-memory buffer intentionally remains
|
||
/// larger for local viewing and copying; uploads retain the device header and
|
||
/// newest log lines within this transport contract.
|
||
const int maxLogUploadBytes = 1 * 1024 * 1024;
|
||
|
||
/// Trims [logs] from the front so `header + logs` fits [maxBytes], keeping the
|
||
/// header intact and never splitting a UTF-8 sequence or a log line.
|
||
String constrainLogUploadPayload({required String header, required String logs, int maxBytes = maxLogUploadBytes}) {
|
||
if (maxBytes <= 0) return '';
|
||
|
||
final headerBytes = utf8.encode(header);
|
||
if (headerBytes.length >= maxBytes) {
|
||
var end = maxBytes;
|
||
while (end > 0 && end < headerBytes.length && (headerBytes[end] & 0xC0) == 0x80) {
|
||
end--;
|
||
}
|
||
return utf8.decode(headerBytes.sublist(0, end));
|
||
}
|
||
|
||
final logBytes = utf8.encode(logs);
|
||
final availableLogBytes = maxBytes - headerBytes.length;
|
||
if (logBytes.length <= availableLogBytes) return '$header$logs';
|
||
|
||
var start = logBytes.length - availableLogBytes;
|
||
while (start < logBytes.length && (logBytes[start] & 0xC0) == 0x80) {
|
||
start++;
|
||
}
|
||
final nextLine = logBytes.indexOf(0x0A, start);
|
||
if (nextLine >= 0 && nextLine + 1 < logBytes.length) {
|
||
start = nextLine + 1;
|
||
}
|
||
return header + utf8.decode(logBytes.sublist(start));
|
||
}
|
||
|
||
/// Posts [payload] to the log relay and returns the short Log ID.
|
||
///
|
||
/// Shared by Settings › Logs and by the startup failure screen, which cannot
|
||
/// reach Settings because the gate it needs has not completed (#1732).
|
||
///
|
||
/// [payload] must already be redacted and allowlisted by the caller; this
|
||
/// function performs no sanitisation of its own.
|
||
Future<String> uploadDiagnosticText(String payload, {MediaServerHttpClient? client}) async {
|
||
final response = await (client ?? httpClient).post(
|
||
logUploadEndpoint,
|
||
body: payload,
|
||
headers: {'Content-Type': 'text/plain'},
|
||
);
|
||
final data = response.data is String ? jsonDecode(response.data as String) : response.data;
|
||
return (data as Map<String, dynamic>)['id'] as String;
|
||
}
|