runConstrained function

Future<PanaProcessResult> runConstrained(
  1. List<String> arguments, {
  2. String? workingDirectory,
  3. Map<String, String>? environment,
  4. Duration? timeout,
  5. int? maxOutputBytes,
  6. bool throwOnError = false,
  7. FutureOr<bool> retryIf(
    1. PanaProcessResult
    )?,
  8. RetryOptions? retryOptions,
})

Runs the arguments as a program|script + its argument list.

Kills the process after timeout (2 minutes if not specified). Kills the process if its output is more than maxOutputBytes (10 MiB if not specified).

If the process is killed, it returns only the first 1000 lines of both stdout and stderr.

When throwOnError is true, non-zero exit codes will throw a ToolException.

When retryIf and retryOptions is set, non-zero exit codes may be retried. This setting forces throwOnError to set true.

Implementation

Future<PanaProcessResult> runConstrained(
  List<String> arguments, {
  String? workingDirectory,
  Map<String, String>? environment,
  Duration? timeout,
  int? maxOutputBytes,
  bool throwOnError = false,
  FutureOr<bool> Function(PanaProcessResult)? retryIf,
  RetryOptions? retryOptions,
}) async {
  retryOptions ??= RetryOptions(maxAttempts: retryIf == null ? 1 : 2);
  return retryOptions.retry(
    () async {
      return await _runConstrained(
        arguments,
        workingDirectory: workingDirectory,
        environment: environment,
        timeout: timeout,
        maxOutputBytes: maxOutputBytes,
        throwOnError: throwOnError || retryOptions!.maxAttempts > 1,
      );
    },
    retryIf: (e) async =>
        retryIf != null && e is ToolException && await retryIf(e.result!),
  );
}