[dart:io] ensure Process.start throws with a stack trace
Change-Id: I8b5d585b10752a873632b3a7b9447214e2d38954
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179640
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Jonah Williams <jonahwilliams@google.com>
diff --git a/sdk/lib/_internal/vm/bin/process_patch.dart b/sdk/lib/_internal/vm/bin/process_patch.dart
index 97426b8..6a158e7 100644
--- a/sdk/lib/_internal/vm/bin/process_patch.dart
+++ b/sdk/lib/_internal/vm/bin/process_patch.dart
@@ -387,6 +387,7 @@
Future<Process> _start() {
var completer = new Completer<Process>();
+ var stackTrace = StackTrace.current;
if (_modeIsAttached(_mode)) {
_exitCode = new Completer<int>();
}
@@ -407,8 +408,10 @@
_modeIsAttached(_mode) ? _exitHandler._nativeSocket : null,
status);
if (!success) {
- completer.completeError(new ProcessException(
- _path, _arguments, status._errorMessage!, status._errorCode!));
+ completer.completeError(
+ new ProcessException(
+ _path, _arguments, status._errorMessage!, status._errorCode!),
+ stackTrace);
return;
}
diff --git a/tests/standalone/io/process_start_exception_test.dart b/tests/standalone/io/process_start_exception_test.dart
index 3a9642e..96d150e 100644
--- a/tests/standalone/io/process_start_exception_test.dart
+++ b/tests/standalone/io/process_start_exception_test.dart
@@ -24,9 +24,10 @@
environment: {"PATH": ""});
processFuture
.then((p) => Expect.fail('got process despite start error'))
- .catchError((error) {
+ .catchError((error, stackTrace) {
Expect.isTrue(error is ProcessException);
Expect.equals(ENOENT, error.errorCode, error.toString());
+ Expect.notEquals(stackTrace.toString(), '');
});
}
diff --git a/tests/standalone_2/io/process_start_exception_test.dart b/tests/standalone_2/io/process_start_exception_test.dart
index 3a9642e..96d150e 100644
--- a/tests/standalone_2/io/process_start_exception_test.dart
+++ b/tests/standalone_2/io/process_start_exception_test.dart
@@ -24,9 +24,10 @@
environment: {"PATH": ""});
processFuture
.then((p) => Expect.fail('got process despite start error'))
- .catchError((error) {
+ .catchError((error, stackTrace) {
Expect.isTrue(error is ProcessException);
Expect.equals(ENOENT, error.errorCode, error.toString());
+ Expect.notEquals(stackTrace.toString(), '');
});
}