recover method
Attempts to recover from an error state.
This method tries to reinitialize the module after an error.
Override onRecover
to implement custom recovery logic.
Returns: True if recovery was successful, false otherwise
Implementation
Future<bool> recover() async {
if (_state != ModuleLifecycleState.error) {
warning('Attempted to recover module $name but it\'s not in error state');
return false;
}
try {
info('Attempting to recover module $name from error: $_lastError');
if (await onRecover()) {
await _transitionTo(ModuleLifecycleState.uninitialized);
await initialize();
info('Module $name recovered successfully');
return true;
} else {
warning('Module $name recovery failed: onRecover returned false');
return false;
}
} catch (e) {
error('Module $name recovery failed with exception: $e');
await _transitionTo(ModuleLifecycleState.error, error: e);
return false;
}
}