passbolt/passbolt_api · error · InternalErrorException

Could not save the secret history.

Error message

Could not save the secret history.

What it means

Thrown by SecretsHistoryTable::create() when save() returns false for an entity that already passed validation — a persistence-layer failure, not a data problem. Raised as InternalErrorException (HTTP 500).

Solutions

  1. Verify the referenced user_id/secret_id rows still exist when the save runs
  2. Run pending migrations to ensure the secrets_history table exists and matches schema
  3. Check database error logs for the exact SQL failure and resolve the constraint
  4. Retry if transient; wrap multi-row history writes in a transaction for consistency

Example fix

// before
$this->SecretsHistory->create($data); // 500 if secret row vanished
// after
if (!$this->Secrets->exists(['id' => $data['secret_id']])) {
    $this->log('Skipping secret history: secret missing ' . $data['secret_id']);
    return;
}
$this->SecretsHistory->create($data);
Defensive patterns

Strategy: try-catch

Validate before calling

if (!$this->Secrets->exists(['id' => $data['secret_id']]) || !$this->Users->exists(['id' => $data['user_id']])) {
    return false; // skip history write
}

Type guard

if (!is_array($data) || empty($data['secret_id']) || empty($data['user_id'])) { return false; }

Try / catch

try {
    $this->SecretsHistory->create($data);
} catch (\Cake\Http\Exception\InternalErrorException $e) {
    $this->log('Secret history save failed: ' . $e->getMessage());
    // verify DB health/migrations; retry transient failures
}

Prevention

When it happens

Trigger: $this->save($secretHistory) returning falsy: foreign-key constraint failure (secret or user row gone), missing secrets_history table, database lock/connection failure, or a beforeSave listener aborting the operation.

Common situations: Secret hard-deleted concurrently while history is being written, skipped migrations leaving secrets_history absent, DB storage/replication problems, and plugin schema drift after upgrades.

Related errors


AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17). Data as JSON: /api/errors/f743aedd0f6f4c80. Report an issue: GitHub.

Appendix: source

Thrown at plugins/PassboltCe/Log/src/Model/Table/SecretsHistoryTable.php:150

     *
     * @param array $data the data
     * @return \Passbolt\Log\Model\Entity\SecretHistory
     * @throws \App\Error\Exception\ValidationException
     * @throws \Cake\Http\Exception\InternalErrorException
     */
    public function create(array $data): SecretHistory
    {
        // Check validation rules.
        $secretHistory = $this->buildEntity($data);
        if ($secretHistory->getErrors()) {
            throw new ValidationException(__('Could not validate secret history data.', true), $secretHistory, $this);
        }

        $secretHistory = $this->save($secretHistory);

        // Check for errors while saving.
        if (!$secretHistory) {
            throw new InternalErrorException('Could not save the secret history.');
        }

        // Check for validation errors. (associated models too).
        if ($secretHistory->getErrors()) {
            throw new ValidationException(__('Could not validate secret history data.'), $secretHistory, $this);
        }

        return $secretHistory;
    }
}

View on GitHub (pinned to 31c1bbc10f)