phacility/phabricator · error · Exception

You can not cycle keys for a file which hasn't yet been…

Error message

You can not cycle keys for a file which hasn't yet been saved.

What it means

State guard in cycleMasterStorageKey: key cycling rewrites stored data in place, so the file must already have an ID and storage handle; calling it on an unsaved PhabricatorFile (no PHID/handle yet) is a programming error.

Solutions

  1. Save the file (persist the object) before cycling its storage key
  2. Reorder calling code so migration happens after initial creation
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at src/applications/files/storage/PhabricatorFile.php:527 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at src/applications/files/storage/PhabricatorFile.php:527

      $engine,
      $data,
      $params);

    $this->setStorageHandle($new_handle);
    $this->setIntegrityHash($integrity_hash);
    $this->save();

    $this->deleteFileDataIfUnused(
      $engine,
      $identifier,
      $old_handle);

    return $this;
  }

  public function cycleMasterStorageKey(PhabricatorFileStorageFormat $format) {
    if (!$this->getID() || !$this->getStorageHandle()) {
      throw new Exception(
        pht("You can not cycle keys for a file which hasn't yet been saved."));
    }

    $properties = $format->cycleStorageProperties();
    $this->setStorageProperties($properties);
    $this->save();

    return $this;
  }

  private function writeToEngine(
    PhabricatorFileStorageEngine $engine,
    $data,
    array $params) {

    $engine_class = get_class($engine);

    $format = $this->newStorageFormat();

View on GitHub (pinned to 5720a38cfe)