Skip to content

Commit

Permalink
Be more informative when credentials have not been found
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegamez committed Apr 25, 2017
1 parent 402dcc1 commit 63b74c1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## Unreleased

* When the credentials file has not been found, a `CredentialsNotFound` exception is thrown,
including the information which paths have been tried.

## 3.0.0 - 2017-04-22

* Moved all classes inside the `Kreait` namespace to avoid possible conflicts with official Firebase PHP libraries
Expand Down
34 changes: 34 additions & 0 deletions src/Firebase/Exception/CredentialsNotFound.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Kreait\Firebase\Exception;

use Kreait\Firebase\Factory;
use Throwable;

class CredentialsNotFound extends LogicException
{
/**
* @var string[]
*/
private $triedPaths;

public function __construct($triedPaths, $message = '', $code = 0, Throwable $previous = null)
{
$message = $message ?: sprintf(
'No service account has been found. Tried [%s]. Please set the path to a valid service account credentials file with %s::%s()',
implode(', ', $triedPaths), Factory::class, 'withCredentials($path)'
);

parent::__construct($message, $code, $previous);

$this->triedPaths = $triedPaths;
}

/**
* @return \string[]
*/
public function getTriedPaths(): array
{
return $this->triedPaths;
}
}
5 changes: 1 addition & 4 deletions src/Firebase/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ private function getServiceAccount(): ServiceAccount
}
// @codeCoverageIgnoreEnd

throw new LogicException(sprintf(
'No service account has been found. Please set the path to a service account credentials file with %s::%s()',
static::class, 'withCredentials($path)'
));
throw new Firebase\Exception\CredentialsNotFound($this->credentialPaths);
}

private function getServiceAccountCandidates(): array
Expand Down

0 comments on commit 63b74c1

Please sign in to comment.