renderCommand<T extends Object> method

Future<OutputContext> renderCommand<T extends Object>(
  1. CommandOutput output, {
  2. required Operation<T> operation,
  3. required OutputWidget textOutputUi,
  4. OutputWidget? fallbackErrorUi,
})

Implementation

Future<OutputContext> renderCommand<T extends Object>(
  final CommandOutput output, {
  required final Operation<T> operation,
  required final OutputWidget textOutputUi,
  final OutputWidget? fallbackErrorUi,
}) async {
  final exceptionHandlingUi = CommonClientExceptionsWidget(
    baseCommand: baseCommand,
    elseWidget: ExceptionHandlingWidget<FailureException>(
      errorWidgetMaker: (final e) => FailureExceptionWidget(e),
      elseWidget: fallbackErrorUi,
    ),
  );

  final ui = CommandWidget.text(
    textOutputUi: textOutputUi,
    textErrorUi: exceptionHandlingUi,
  );

  final context = await output.render(operation: operation, ui: ui);

  // Re-throw exceptions as appropriate so that Sentry reporting and process exit
  // are performed.
  final qe = context.find<QualifiedException>();
  if (qe != null) {
    if (qe.exception case final FailureException f) {
      final nested = f.nestedException;
      if (nested != null) {
        throw UnexpectedErrorExitException(
          f.reason,
          nested,
          f.nestedStackTrace,
        );
      }
      throw ErrorExitException(f.reason, null, f.nestedStackTrace);
    }
    Error.throwWithStackTrace(qe.exception, qe.stackTrace);
  }

  return context;
}