formatTapResult function

int formatTapResult(
  1. TapResult result
)

Formats a TapResult to stdout/stderr and returns the exit code.

Exposed so other CLI adapters (e.g. native_tap_cli) can reuse the same result formatting without duplicating the switch.

Implementation

int formatTapResult(TapResult result) {
  switch (result) {
    case TapSuccess(:final widgetType, :final x, :final y, :final warning):
      final warningSuffix = warning != null ? ' WARNING=$warning' : '';
      stdout.writeln('TAPPED=$widgetType X=$x Y=$y$warningSuffix');
      return 0;
    case TapNoFdbHelper():
      stderr.writeln(
        'ERROR: fdb_helper not detected in running app. '
        'Add fdb_helper package to your Flutter app and call '
        'FdbBinding.ensureInitialized() in main()',
      );
      return 1;
    case TapUnexpectedDescribeResponse():
      stderr.writeln('ERROR: Unexpected response from ext.fdb.describe');
      return 1;
    case TapRelayedDescribeError(:final message):
      stderr.writeln('ERROR: $message');
      return 1;
    case TapRefNotFound(:final ref):
      stderr.writeln(
        'ERROR: No interactive element with ref @$ref. '
        'Run `fdb describe` to see available refs.',
      );
      return 1;
    case TapRelayedError(:final message):
      stderr.writeln('ERROR: $message');
      return 1;
    case TapUnexpectedResponse(:final raw):
      stderr.writeln('ERROR: Unexpected response from ext.fdb.tap: $raw');
      return 1;
    case TapAppDied(:final logLines, :final reason):
      throw AppDiedException(logLines: logLines, reason: reason);
    case TapError(:final message):
      stderr.writeln('ERROR: $message');
      return 1;
  }
}