runStage<T> function

Future<T> runStage<T>(
  1. RenderPhase phase,
  2. Future<T> body()
)

Runs body, stamping phase onto any FluvieRenderException it throws (when not already stamped) so the failure records which render stage broke.

The exact exception subtype and stack trace are preserved (a FluvieEncodeException keeps its exit code and stderr), so callers still catch and inspect it as before — now with stage populated.

Implementation

Future<T> runStage<T>(RenderPhase phase, Future<T> Function() body) async {
  try {
    return await body();
  } on FluvieRenderException catch (error) {
    error.stage ??= phase;
    rethrow;
  }
}