{"record":{"id":"3e3191553f0dd68b","repo":"phacility/phabricator","slug":"unable-to-load-subscription-with-phid-s","errorCode":null,"errorMessage":"Unable to load subscription with PHID \"%s\".","messagePattern":"Unable to load subscription with PHID \"(.+?)\"\\.","errorType":"console","errorClass":"PhutilArgumentUsageException","httpStatus":null,"severity":"error","filePath":"src/applications/phortune/management/PhabricatorPhortuneManagementInvoiceWorkflow.php","lineNumber":67,"sourceCode":"  public function execute(PhutilArgumentParser $args) {\n    $console = PhutilConsole::getConsole();\n    $viewer = $this->getViewer();\n\n    $subscription_phid = $args->getArg('subscription');\n    if (!$subscription_phid) {\n      throw new PhutilArgumentUsageException(\n        pht(\n          'Specify which subscription to invoice with %s.',\n          '--subscription'));\n    }\n\n    $subscription = id(new PhortuneSubscriptionQuery())\n      ->setViewer($viewer)\n      ->withPHIDs(array($subscription_phid))\n      ->needTriggers(true)\n      ->executeOne();\n    if (!$subscription) {\n      throw new PhutilArgumentUsageException(\n        pht(\n          'Unable to load subscription with PHID \"%s\".',\n          $subscription_phid));\n    }\n\n    $now = $args->getArg('now');\n    $now = $this->parseTimeArgument($now);\n    if (!$now) {\n      $now = PhabricatorTime::getNow();\n    }\n\n    $time_guard = PhabricatorTime::pushTime($now, date_default_timezone_get());\n\n    $console->writeOut(\n      \"%s\\n\",\n      pht(\n        'Set current time to %s.',\n        phabricator_datetime(PhabricatorTime::getNow(), $viewer)));","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/phortune/management/PhabricatorPhortuneManagementInvoiceWorkflow.php#L49-L85","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-copy the PHID from the subscription's detail page in the web UI and retry.","Confirm the subscription actually exists: inspect the phortune_subscription table or the account's subscription list in Phortune.","Run the command as (or on behalf of) a user who can see the account and provider for that subscription.","Validate the PHID shape before running, e.g. with phid_get_type($phid), to catch truncation."],"exampleFix":"# before\n$ ./bin/phortune invoice --subscription PHID-PSUB-oops\n\n# after\n# 1. open the subscription page in Phortune, copy the real PHID\n$ ./bin/phortune invoice --subscription PHID-PSUB-1234abcd","handlingStrategy":"validation","validationCode":"// Validate the PHID's type before running the expensive workflow.\nif (!phid_get_type($subscription_phid) === null) {\n  // malformed PHID: fail fast\n}\n// Or pre-flight load it the same way the workflow does:\n$sub = id(new PhortuneSubscriptionQuery())\n  ->setViewer($viewer)\n  ->withPHIDs(array($subscription_phid))\n  ->executeOne();\nif (!$sub) {\n  // wrong PHID, deleted subscription, or invisible to this viewer:\n  // stop here with a clear message instead of running the command","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Copy PHIDs from the UI object header, never retype them.","Run management workflows as an admin who can see the account and payment provider owning the subscription.","Cross-check the subscription exists via the account's subscription list or the phortune_subscription table before scripting invoices."],"tags":["php","phabricator","phortune","cli","not-found","billing"],"backgroundTag":"entity-not-found","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}