phacility/phabricator · error · PhutilArgumentUsageException

Unable to load subscription with PHID "%s".

Error message

Unable to load subscription with PHID "%s".

What it means

PhutilArgumentUsageException thrown by the phortune invoice workflow when the PhortuneSubscriptionQuery with ->withPHIDs(array($subscription_phid))->needTriggers(true) returns no result. The query runs with the workflow's viewer, so a subscription can fail to load both because the PHID is wrong and because the acting user cannot see it. Aborts with usage text and non-zero exit.

Source

Thrown at src/applications/phortune/management/PhabricatorPhortuneManagementInvoiceWorkflow.php:67

  public function execute(PhutilArgumentParser $args) {
    $console = PhutilConsole::getConsole();
    $viewer = $this->getViewer();

    $subscription_phid = $args->getArg('subscription');
    if (!$subscription_phid) {
      throw new PhutilArgumentUsageException(
        pht(
          'Specify which subscription to invoice with %s.',
          '--subscription'));
    }

    $subscription = id(new PhortuneSubscriptionQuery())
      ->setViewer($viewer)
      ->withPHIDs(array($subscription_phid))
      ->needTriggers(true)
      ->executeOne();
    if (!$subscription) {
      throw new PhutilArgumentUsageException(
        pht(
          'Unable to load subscription with PHID "%s".',
          $subscription_phid));
    }

    $now = $args->getArg('now');
    $now = $this->parseTimeArgument($now);
    if (!$now) {
      $now = PhabricatorTime::getNow();
    }

    $time_guard = PhabricatorTime::pushTime($now, date_default_timezone_get());

    $console->writeOut(
      "%s\n",
      pht(
        'Set current time to %s.',
        phabricator_datetime(PhabricatorTime::getNow(), $viewer)));

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Re-copy the PHID from the subscription's detail page in the web UI and retry.
  2. Confirm the subscription actually exists: inspect the phortune_subscription table or the account's subscription list in Phortune.
  3. Run the command as (or on behalf of) a user who can see the account and provider for that subscription.
  4. Validate the PHID shape before running, e.g. with phid_get_type($phid), to catch truncation.

Example fix

# before
$ ./bin/phortune invoice --subscription PHID-PSUB-oops

# after
# 1. open the subscription page in Phortune, copy the real PHID
$ ./bin/phortune invoice --subscription PHID-PSUB-1234abcd
Defensive patterns

Strategy: validation

Validate before calling

// Validate the PHID's type before running the expensive workflow.
if (!phid_get_type($subscription_phid) === null) {
  // malformed PHID: fail fast
}
// Or pre-flight load it the same way the workflow does:
$sub = id(new PhortuneSubscriptionQuery())
  ->setViewer($viewer)
  ->withPHIDs(array($subscription_phid))
  ->executeOne();
if (!$sub) {
  // wrong PHID, deleted subscription, or invisible to this viewer:
  // stop here with a clear message instead of running the command

Prevention

When it happens

Trigger: Passing a typo'd or truncated PHID to --subscription; a PHID copied from a different install; a subscription that was deleted; or running the workflow as a viewer with no visibility into the payment provider/account owning the subscription.

Common situations: PHIDs copy-pasted across environments (dev vs prod); stale PHIDs in runbooks after subscriptions were recreated; permissions of the CLI acting user differing from the admin who created the subscription.

Related errors


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