failed static method

void failed(
  1. String message, {
  2. String? suggestion,
  3. List<String>? examples,
  4. bool isExit = true,
  5. int statusExit = 1,
})

Reports operation failure with enhanced error information.

Displays an error message followed by optional suggestions and examples, and terminates the application with a red "FAILED" indicator.

Parameters:

  • message: Primary error message to display
  • suggestion: Optional suggestion for resolving the error
  • examples: Optional list of example commands to fix the issue
  • isExit: Whether to exit the process (default: true)
  • statusExit: Exit code to use (default: 1)

Example:

StatusHelper.failed(
  'Configuration file not found',
  suggestion: 'Run "morpheme init" to create a new configuration file',
  examples: ['morpheme init', 'morpheme config'],
);
// Output: (in red text)
// Configuration file not found
//
// Suggestion: Run "morpheme init" to create a new configuration file
//
// Example commands:
//   morpheme init
//   morpheme config
//
// FAILED

Implementation

static void failed(
  String message, {
  String? suggestion,
  List<String>? examples,
  bool isExit = true,
  int statusExit = 1,
}) {
  printerrMessage(red(message));

  if (suggestion != null) {
    printerrMessage(yellow('\nSuggestion: $suggestion'));
  }

  if (examples != null && examples.isNotEmpty) {
    printerrMessage(cyan('\nExample commands:'));
    for (final example in examples) {
      printerrMessage(cyan('  $example'));
    }
  }

  printerrMessage(red('\nFAILED'));
  if (isExit) {
    exit(statusExit);
  }
}