diff options
| author | Teddy Wing | 2021-05-22 20:05:42 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2021-05-22 20:05:42 +0200 | 
| commit | fdee5a8b0730921d072bfc700e120299c0f7bc79 (patch) | |
| tree | 55718da404ae4d1d62638c6618b1c42fcc7c874a /src | |
| parent | 85f6e0a660439ca7ce0e42220fab9491d2d5a857 (diff) | |
| download | google-calendar-rsvp-fdee5a8b0730921d072bfc700e120299c0f7bc79.tar.bz2 | |
secret_from_file(): Remove `unwrap`s
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 16 | 
1 files changed, 7 insertions, 9 deletions
| diff --git a/src/main.rs b/src/main.rs index f46c745..ad7c0f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -121,7 +121,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {  }  async fn rsvp(event_id: &str, response: &EventResponseStatus) -> Event { -    let secret = secret_from_file(); +    let secret = secret_from_file().unwrap();      let auth = oauth2::InstalledFlowAuthenticator::builder(          secret, @@ -174,19 +174,17 @@ async fn rsvp(event_id: &str, response: &EventResponseStatus) -> Event {      res.1  } -fn secret_from_file() -> oauth2::ApplicationSecret { +fn secret_from_file() -> anyhow::Result<oauth2::ApplicationSecret> {      let f = fs::File::open(          home::home_dir() -            .unwrap() +            .ok_or(anyhow::anyhow!("error getting home directory"))?              .join(".google-service-cli/calendar3-secret.json"), -    ).unwrap(); +    )?; -    let console_secret: oauth2::ConsoleApplicationSecret = serde_json::from_reader(f).unwrap(); +    let console_secret: oauth2::ConsoleApplicationSecret = serde_json::from_reader(f)?; -    match console_secret.installed { -        Some(secret) => secret, -        None => todo!(), -    } +    console_secret.installed +        .ok_or(anyhow::anyhow!("OAuth2 application secret not found"))  }  fn event_id_from_base64(event_id: &str) -> anyhow::Result<String> { | 
