guardWrite<T> function
Runs a write or a delete, reporting any failure that isn't already a
LocalDataSourceException as a DataSourceWriteException with message.
Implementation
Future<T> guardWrite<T>(String message, Future<T> Function() action) async {
try {
return await action();
} catch (error, stackTrace) {
if (error is LocalDataSourceException) rethrow;
Error.throwWithStackTrace(
DataSourceWriteException(message, error),
stackTrace,
);
}
}