Skip to content

Improve SubprocessException #3679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions tool/src/subprocess_launcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';

class SubprocessException implements Exception {}

class SubprocessLauncher {
final String context;
final Map<String, String> defaultEnvironment;
Expand Down Expand Up @@ -121,15 +119,19 @@ class SubprocessLauncher {
workingDirectory: workingDirectory,
environment: environment,
includeParentEnvironment: includeParentEnvironment);
// Stream stdout and stderr to _this_ process's stdout and stderr.
var stdoutFuture = _printStream(process.stdout, stdout,
prefix: prefix, filter: jsonCallback);
var stderrFuture = _printStream(process.stderr, stderr,
prefix: prefix, filter: jsonCallback);
await Future.wait([stderrFuture, stdoutFuture, process.exitCode]);
var (_, _, exitCode) =
await (stdoutFuture, stderrFuture, process.exitCode).wait;

var exitCode = await process.exitCode;
if (exitCode != 0) {
throw SubprocessException();
throw SubprocessException(
command: [executable, ...arguments].join(' '),
workingDirectory: workingDirectory,
exitCode: exitCode);
}
return jsonObjects;
}
Expand Down Expand Up @@ -174,3 +176,21 @@ class SubprocessLauncher {

static final _quotables = RegExp(r'[ "\r\n\$]');
}

Copy link
Member

@kevmoo kevmoo Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not :D but I guess we could shave a few lines.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all of those folks who want to catch...uh...

You know, not a biggy. Just pondering...

/// An exception that represents an issue during subprocess execution.
class SubprocessException implements Exception {
final String command;
final String? workingDirectory;
final int exitCode;

SubprocessException(
{required this.command,
required this.workingDirectory,
required this.exitCode});

@override
String toString() => 'SubprocessException['
'command: "$command", '
'workingDirectory: "${workingDirectory ?? '(null)'}", '
'exitCode: $exitCode]';
}