interpretExitCode function

String? interpretExitCode(
  1. String command,
  2. int exitCode
)

Semantic exit code interpretation.

Implementation

String? interpretExitCode(String command, int exitCode) {
  if (exitCode == 0) return null;

  final baseCmd = command.trim().split(RegExp(r'\s+')).first;

  return switch (baseCmd) {
    'grep' ||
    'rg' ||
    'ag' ||
    'ack' when exitCode == 1 => 'No matches found (not an error)',
    'find' || 'fd' when exitCode == 1 =>
      'Partial results (some directories inaccessible)',
    'diff' when exitCode == 1 => 'Differences found (not an error)',
    'test' || '[' when exitCode == 1 => 'Condition evaluated to false',
    'curl' when exitCode == 6 => 'Could not resolve host',
    'curl' when exitCode == 7 => 'Failed to connect to host',
    'curl' when exitCode == 28 => 'Operation timed out',
    _ => null,
  };
}