phacility/phabricator · error · PhutilArgumentUsageException

Specify one or more queries to export with "--query".

Error message

Specify one or more queries to export with "--query".

What it means

The export workflow needs at least one query selected with --query. With no query keys at all ($args->getArg('query') empty), it throws this usage exception immediately. Query keys are either builtin names (like 'all') or the saved-query keys visible in the web UI search URL (queryKey parameter).

Source

Thrown at src/applications/transactions/bulk/management/PhabricatorBulkManagementExportWorkflow.php:157

        "%s\n",
        pht(
          'Exported data to "%s".',
          Filesystem::readablePath($output_path)));
    } else {
      foreach ($iterator as $chunk) {
        echo $chunk;
      }
    }

    return 0;
  }

  private function newQueries(PhutilArgumentParser $args) {
    $viewer = $this->getViewer();

    $query_keys = $args->getArg('query');
    if (!$query_keys) {
      throw new PhutilArgumentUsageException(
        pht(
          'Specify one or more queries to export with "--query".'));
    }

    $engine_classes = id(new PhutilClassMapQuery())
      ->setAncestorClass('PhabricatorApplicationSearchEngine')
      ->execute();

    $class = $args->getArg('class');
    if (strlen($class)) {

      $class_list = array();
      foreach ($engine_classes as $class_name => $engine_object) {
        $can_export = id(clone $engine_object)
          ->setViewer($viewer)
          ->canExport();
        if ($can_export) {
          $class_list[] = $class_name;

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Pass a saved query key: run the search in the web UI and copy the queryKey from the URL.
  2. Pass a builtin query name such as --query all together with --class <EngineClassName>.
  3. Assert the variable is nonempty in scripts before invoking: test -n "$QUERY" || exit 2.

Example fix

# before
bin/bulk export --format csv --output -
# after
bin/bulk export --format csv --output - --class ManiphestTaskSearchEngine --query all
Defensive patterns

Strategy: validation

Validate before calling

test -n "$QUERY" || { echo 'QUERY is empty; refusing to export' >&2; exit 2; }
bin/bulk export --query "$QUERY" --output -

Prevention

When it happens

Trigger: Calling `bin/bulk export` with --format/--output but no --query argument; passing --query via a wrapper script where the variable expanded to an empty value.

Common situations: Converting a UI search into a CLI export and forgetting the query key; scripts where an unquoted or unset $QUERY variable expanded to nothing; copying a command template but deleting the query part.

Related errors


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