phacility/phabricator · warning · PhutilArgumentUsageException

Argument "%s" is not a valid message ID.

Error message

Argument "%s" is not a valid message ID.

What it means

show-outbound validates every --id value with ctype_digit() before querying: each must be a plain string of decimal digits. Negative numbers (leading '-'), whitespace, hex, scientific notation, or any non-digit character fails. The check exists because the IDs are interpolated into an `%Ld` (list of integers) query.

Source

Thrown at src/applications/metamta/management/PhabricatorMailManagementShowOutboundWorkflow.php:42

              'file and then open it in a browser.'),
          ),
        ));
  }

  public function execute(PhutilArgumentParser $args) {
    $console = PhutilConsole::getConsole();

    $ids = $args->getArg('id');
    if (!$ids) {
      throw new PhutilArgumentUsageException(
        pht(
          "Use the '%s' flag to specify one or more messages to show.",
          '--id'));
    }

    foreach ($ids as $id) {
      if (!ctype_digit($id)) {
        throw new PhutilArgumentUsageException(
          pht(
            'Argument "%s" is not a valid message ID.',
            $id));
      }
    }

    $messages = id(new PhabricatorMetaMTAMail())->loadAllWhere(
      'id IN (%Ld)',
      $ids);

    if ($ids) {
      $ids = array_fuse($ids);
      $missing = array_diff_key($ids, $messages);
      if ($missing) {
        throw new PhutilArgumentUsageException(
          pht(
            'Some specified messages do not exist: %s',
            implode(', ', array_keys($missing))));

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Pass plain positive integers, e.g. `--id 123`.
  2. Sanitize generated IDs: strip non-digits (`preg_replace('/[^0-9]/', '', $id)`) before building the command.
  3. Reject zero-padded or signed values at the source rather than on the command line.

Example fix

// before
$ bin/mail show-outbound --id '#456'
// Exception: Argument "#456" is not a valid message ID.

// after
$ bin/mail show-outbound --id 456
Defensive patterns

Strategy: type-guard

Type guard

// Guard each ID with the exact rule the workflow applies (ctype_digit):
function is_valid_mail_id($id) {
  return is_string($id) && ctype_digit($id);
}
$ids = array_values(array_filter($ids, 'is_valid_mail_id'));
if (!$ids) {
  fwrite(STDERR, "No valid message IDs.\n");
  exit(1);
}

Prevention

When it happens

Trigger: `--id -5`, `--id 12a`, `--id 1e3`, `--id ' 123'`, or IDs assembled by string concatenation that leaves stray characters.

Common situations: Generated command lines from templates that include formatting characters; locales or tools that insert grouping separators into numbers.

Related errors


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