UNSAFE<T> function

T UNSAFE<T>(
  1. @mustBeAnonymous @noFutures T block()
)

Executes a block of code that is considered UNSAFE, allowing the use of methods like Outcome.unwrap. This function provides no actual safety guarantees; it only serves as a marker for linter rules and to signal to developers that the contained code can throw exceptions from Outcome operations.

Use this to explicitly acknowledge that you are handling a potentially failing operation outside the Outcome context.

Implementation

// ignore: non_constant_identifier_names
T UNSAFE<T>(@mustBeAnonymous @noFutures T Function() block) {
  assert(!isSubtype<T, Future<Object>>(), '$T must never be a Future.');
  try {
    return block();
  } catch (e, _) {
    // We may want to do something here at some point.
    rethrow;
  }
}