Files
sdk/pkg/testing/lib/src/error_handling.dart
T
Devon Carew b27709f1b8 [pkg/testing] analyze using package:lints
Change-Id: If43bc64029ac00575dc154b797fc7630d4dac82e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/250764
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
2022-07-06 18:55:40 +00:00

32 lines
804 B
Dart

// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE.md file.
library testing.error_handling;
import 'dart:async' show Future;
import 'dart:io' show exitCode, stderr;
import 'dart:isolate' show ReceivePort;
import 'log.dart';
Future<T?> withErrorHandling<T>(Future<T> f(), {Logger? logger}) async {
final ReceivePort port = ReceivePort();
try {
return await f();
} catch (e, trace) {
exitCode = 1;
stderr.writeln(e);
// ignore: unnecessary_null_comparison
if (trace != null) {
stderr.writeln(trace);
}
logger?.noticeFrameworkCatchError(e, trace);
return null;
} finally {
port.close();
}
}