diet-guard/app/lib/services/sync_attempt.dart
Krzysztof kuhy Rudnicki 5add5fa55f
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint) (push) Waiting to run
Tests / test (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Report sync failures; dev extra; deploy script
The phone showed "Not syncing" with no way to learn why: a release
build keeps no log. attemptSync now records the outcome and files a
sync.failed report to the board with the exception. A refresh error
after a landed sync no longer marks it failed.

Also: hypothesis in pyproject's dev extra; gatelock 0.16.0,
claude-agent-sdk 0.2.184 and stale app pins bumped;
scripts/deploy.sh as the CLAUDE.md deploy command.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 22:32:07 +01:00

43 lines
1.4 KiB
Dart

/// Runs one sync and records its outcome for the "not syncing" banner.
///
/// The banner said "Not syncing" on a phone whose sync looked fine, and the
/// release build keeps no log that could say why (see `sync_health.dart`).
/// So a failure here also goes to the board through the app-wide reporter:
/// the next one files its own ticket with the exception that caused it.
/// Inside a WorkManager isolate no reporter is installed, so a background
/// failure is only recorded, not filed.
///
/// Only the sync itself is timed in: screen refreshes after a landed sync
/// run outside, so their errors never mark a working sync as failed.
library;
import 'dart:developer';
import 'package:crdt_sync_flutter/crdt_sync_flutter.dart' show AppErrors;
import 'package:diet_guard_app/services/sync_health.dart';
/// Runs [sync]; records success, or failure plus a `sync.failed` report.
///
/// Returns whether the sync landed. Never throws.
Future<bool> attemptSync(Future<void> Function() sync) async {
try {
await sync();
} on Object catch (error, stackTrace) {
log(
'diet_guard sync failed',
level: 1000,
error: error,
stackTrace: stackTrace,
);
AppErrors.instance?.reporter.report(
'sync.failed',
error,
stack: stackTrace,
);
await SyncHealth.recordFailure();
return false;
}
await SyncHealth.recordSuccess();
return true;
}