diff options
author | Ben PĆ¼schel <ben.pueschel2004@gmail.com> | 2024-09-30 16:16:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-30 16:16:11 +0200 |
commit | 4164ea9ec67c1a08d24acd71885a1a4193037c1c (patch) | |
tree | fe6c66804ccf86285b503bdbfb8211cbe4463485 /src/lib.rs | |
parent | 6ca41409d57cc1011a7b3af8969c37f98ad99fa9 (diff) |
fix(installation)!: Return Result instead of panicking in `Octocrab::installation` (#687)
* fix(installation)!: Return Result instead of panicking
Refs: #641
BREAKING CHANGE: `Octocrab::installation` now returns a Result, changing
the public API.
* refactor(error)!: add `installation` variant
Adds a new variant `Installation` on the Error enum and also makes the
enum non-exhaustive to prevent further breaking changes when adding new
variants in the future.
* style: remove unused import
* style: remove unnecessary error let binding
* refactor: remove installation error message
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -1010,20 +1010,22 @@ impl Octocrab { /// then obtain an installation ID, and then pass that here to /// obtain a new `Octocrab` with which you can make API calls /// with the permissions of that installation. - pub fn installation(&self, id: InstallationId) -> Octocrab { + pub fn installation(&self, id: InstallationId) -> Result<Octocrab> { let app_auth = if let AuthState::App(ref app_auth) = self.auth_state { app_auth.clone() } else { - panic!("Github App authorization is required to target an installation"); + return Err(Error::Installation { + backtrace: Backtrace::generate(), + }); }; - Octocrab { + Ok(Octocrab { client: self.client.clone(), auth_state: AuthState::Installation { app: app_auth, installation: id, token: CachedToken::default(), }, - } + }) } /// Similar to `installation`, but also eagerly caches the installation @@ -1036,7 +1038,7 @@ impl Octocrab { &self, id: InstallationId, ) -> Result<(Octocrab, SecretString)> { - let crab = self.installation(id); + let crab = self.installation(id)?; let token = crab.request_installation_auth_token().await?; Ok((crab, token)) } @@ -1499,7 +1501,9 @@ impl Octocrab { { (app, installation, token) } else { - panic!("Installation not configured"); + return Err(Error::Installation { + backtrace: Backtrace::generate(), + }); }; let mut request = Builder::new(); let mut sensitive_value = |