runRestorePhases static method

  1. @visibleForTesting
Future<void> runRestorePhases({
  1. required Future<void> clear(),
  2. required Future<void> rewrite(),
})

Runs clear then rewrite, wrapping failures with a phase-named StateError.

Implementation

@visibleForTesting
static Future<void> runRestorePhases({
  required Future<void> Function() clear,
  required Future<void> Function() rewrite,
}) async {
  return await RunnerBenchmark.async('lifecycle', 'runRestorePhases',
      () async {
    try {
      await clear();
    } catch (error, stackTrace) {
      Error.throwWithStackTrace(
        StateError(
          'AppSessionSnapshot restore failed during clear phase: $error',
        ),
        stackTrace,
      );
    }
    try {
      await rewrite();
    } catch (error, stackTrace) {
      Error.throwWithStackTrace(
        StateError(
          'AppSessionSnapshot restore failed during rewrite phase: $error',
        ),
        stackTrace,
      );
    }
  });
}