phacility/phabricator · error · Exception

No public key was provided.

Error message

No public key was provided.

What it means

PhabricatorAuthSSHPublicKey::newFromRawKey() trims the submitted key text and immediately throws if nothing remains. It is the entry point for parsing any uploaded SSH public key (type + base64 body + comment), so empty input cannot be parsed.

Source

Thrown at src/applications/auth/sshkey/PhabricatorAuthSSHPublicKey.php:28

  private $comment;

  private function __construct() {
    // <internal>
  }

  public static function newFromStoredKey(PhabricatorAuthSSHKey $key) {
    $public_key = new PhabricatorAuthSSHPublicKey();
    $public_key->type = $key->getKeyType();
    $public_key->body = $key->getKeyBody();
    $public_key->comment = $key->getKeyComment();

    return $public_key;
  }

  public static function newFromRawKey($entire_key) {
    $entire_key = trim($entire_key);
    if (!strlen($entire_key)) {
      throw new Exception(pht('No public key was provided.'));
    }

    $parts = str_replace("\n", '', $entire_key);

    // The third field (the comment) can have spaces in it, so split this
    // into a maximum of three parts.
    $parts = preg_split('/\s+/', $parts, 3);

    if (preg_match('/private\s*key/i', $entire_key)) {
      // Try to give the user a better error message if it looks like
      // they uploaded a private key.
      throw new Exception(pht('Provide a public key, not a private key!'));
    }

    switch (count($parts)) {
      case 1:
        throw new Exception(
          pht('Provided public key is not properly formatted.'));

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Paste the full public key line (e.g. 'ssh-ed25519 AAAA... comment') and resubmit
  2. If this comes from a file upload, verify the file actually read non-empty contents before submission
  3. Check for form/JS bugs that clear or never populate the key field
Defensive patterns

Strategy: validation

Validate before calling

// Before calling PhabricatorAuthSSHPublicKey::newFromRawKey():
$raw = trim($submitted_key_text);
if (!strlen($raw)) {
  // Block the empty submission in the form layer with a field error,
  // not a fatal after submission.
  $form_field->setError(pht('Required')); 
}

Try / catch

try {
  $public_key = PhabricatorAuthSSHPublicKey::newFromRawKey($raw);
} catch (Exception $ex) {
  // Attach the message ('No public key was provided.') to the form field.
  $e_key = pht('Required');
  $errors[] = $ex->getMessage();
}

Prevention

When it happens

Trigger: Calling newFromRawKey('') or with whitespace-only input - e.g. an SSH key upload form submitted with an empty textarea, or upstream code passing a failed file read (empty string) instead of the key contents.

Common situations: Users clicking submit before pasting; client-side upload where reading the file failed silently and '' was posted; automation passing an unset variable.

Related errors


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