fail function

Never fail(
  1. String message, {
  2. int exitCode = 1,
})

Prints message to stderr and exits the current script.

Within a Script.capture block, this throws a ScriptException that causes the script to exit with the given exitCode. Elsewhere, it exits the Dart process entirely.

Implementation

Never fail(String message, {int exitCode = 1}) {
  currentStderr.writeln(message);

  var scriptName = Zone.current[scriptNameKey];
  if (scriptName is String) {
    throw ScriptException(scriptName, exitCode);
  } else {
    exit(exitCode);
  }
}