execute<T> method
Executes a standard synchronous operation closure block securely.
Returns a Result.success containing the computation data if execution is optimal.
Automatically intercepts any thrown runtime errors and transforms them using _handleError.
An optional context description can be specified to enrich debug tracking logs.
Implementation
Result<T> execute<T>(
T Function() operation, {
String? context,
}) {
try {
final data = operation();
_logger
.info('Operation successful${context != null ? " in $context" : ""}');
return Result.success(data);
} catch (e, stackTrace) {
return _handleError<T>(e, stackTrace, context);
}
}