Skip to content

Consolidate exit-code parameters on runCommand with ExpectedExit - #196479

Queued
andywolff wants to merge 2 commits into
flutter:masterfrom
andywolff:run-command-expected-exit
Queued

andywolff wants to merge 2 commits into
flutter:masterfrom
andywolff:run-command-expected-exit

Conversation

@andywolff

Copy link
Copy Markdown
Contributor

Fixes #196126

Replaces the overlapping exit-code flags on runCommand with a single ExpectedExit type, migrates the existing callers across dev/bots/, and removes a couple of unused helpers found during the cleanup.

@andywolff andywolff added the CICD Run CI/CD label Nov 12, 2026
@andywolff
andywolff force-pushed the run-command-expected-exit branch from 039d59a to 2d299ca Compare November 12, 2026 22:18
@andywolff
andywolff marked this pull request as ready for review November 12, 2026 22:20
@andywolff
andywolff requested a review from b-luk November 12, 2026 22:20

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the process exit code validation in runCommand by replacing the checkExitCode, expectNonZeroExit, and expectedExitCode parameters with a unified ExpectedExit sealed class. The runAndGetStdout helper function is removed, and all call sites of runCommand across the codebase are updated to use the new ExpectedExit options. Additionally, corresponding unit tests are updated to verify the behavior of each ExpectedExit type. There are no review comments, and no further feedback is provided.

Comment thread dev/bots/run_command.dart Outdated
if (checkExitCode &&
((result.exitCode == 0) == expectNonZeroExit ||
(expectedExitCode != null && result.exitCode != expectedExitCode))) {
final String? expectedExitDescription = switch (expectedExit) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

expectedExitDescription is serving two purposes: 1. indicates whether exit code validation failed, and 2. Provides a single-word description used in the reported error message.

Neither of these purposes is immediately obvious from the variable's name or on a quick read of the switch expression. You have to parse a somewhat dense switch expression to figure out what is going on.

Instead of having this variable and switch expression serve these two purposes, what do you think about making ExpectedExit responsible for these two things? I'm not very familiar with modern Dart syntax and patterns, so I don't know if this is actually better. But to my Dart-inexperienced eyes it seems more readable. Something like:

sealed class ExpectedExit {
  ...
  bool matches(int actualExitCode);
  String get description;
}

final class _ExpectedExitCode extends ExpectedExit {
  ...
  @override
  bool matches(int actualExitCode) => actualExitCode == exitCode;

  @override
  String get description => exitCode == 0 ? 'zero' : '$exitCode';
}

final class _ExpectedNonZeroExit extends ExpectedExit {
  ...
  @override
  bool matches(int actualExitCode) => actualExitCode != 0;

  @override
  String get description => 'non-zero';
}

final class _ExpectedAnyExit extends ExpectedExit {
  ...
  @override
  bool matches(int actualExitCode) => true;

  @override
  String get description => 'any';
}

and then the code here would be:

  if (!expectedExit.matches(result.exitCode)) {
    ...
    '...but expected ${expectedExit.description} exit code...'
    ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah that's a lot better, thanks. Done

@andywolff
andywolff requested a review from b-luk November 13, 2026 19:51
@andywolff andywolff added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 13, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 13, 2026
@auto-submit

auto-submit Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/196479, because - The status or check suite Presubmit has failed. Please fix the issues identified (or deflake) before re-applying this label.

@andywolff andywolff added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 13, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consolidate exit-code parameters on runCommand in dev/bots/run_command.dart

2 participants