phacility/phabricator · error · PhutilArgumentUsageException

Value provided to "--count" must be a nonzero, positive numb

Error message

Value provided to "--count" must be a nonzero, positive number.

What it means

A PhutilArgumentUsageException from `bin/drydock lease` when --count parses (via getArgAsInteger) to a value below 1. --count sets how many identical leases the single invocation creates (default 1); zero or negative counts are meaningless and rejected before any lease is created.

Source

Thrown at src/applications/drydock/management/DrydockManagementLeaseWorkflow.php:66

    if (!phutil_nonempty_string($resource_type)) {
      throw new PhutilArgumentUsageException(
        pht(
          'Specify a resource type with "--type".'));
    }

    $until = $args->getArg('until');
    if (phutil_nonempty_string($until)) {
      $until = strtotime($until);
      if ($until <= 0) {
        throw new PhutilArgumentUsageException(
          pht(
            'Unable to parse argument to "--until".'));
      }
    }

    $count = $args->getArgAsInteger('count');
    if ($count < 1) {
      throw new PhutilArgumentUsageException(
        pht(
          'Value provided to "--count" must be a nonzero, positive '.
          'number.'));
    }

    $attributes_file = $args->getArg('attributes');
    if (phutil_nonempty_string($attributes_file)) {
      if ($attributes_file == '-') {
        echo tsprintf(
          "%s\n",
          pht('Reading JSON attributes from stdin...'));
        $data = file_get_contents('php://stdin');
      } else {
        $data = Filesystem::readFile($attributes_file);
      }

      $attributes = phutil_json_decode($data);
    } else {

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Pass a positive integer, e.g. `--count 3` to acquire three identical leases.
  2. Skip the invocation entirely when the computed count is 0 rather than calling with the flag.

Example fix

# before
bin/drydock lease --type host --count 0

# after
bin/drydock lease --type host --count 3
Defensive patterns

Strategy: validation

Validate before calling

$count = (int)$count;
if ($count < 1) {
  throw new InvalidArgumentException(
    '--count must be a positive integer, got '.$count);
}

Prevention

When it happens

Trigger: `bin/drydock lease --type host --count 0`, `--count -5`, or a non-numeric value that getArgAsInteger coerces/rejects; a computed count in a script that evaluates to 0 when a list is empty.

Common situations: Fan-out scripts computing count = number of items and passing 0 for an empty batch; treating --count as a lease ID or offset by mistake.

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/8820b2c4f1157448. Report an issue: GitHub.