aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorTeddy Wing2021-05-22 20:05:42 +0200
committerTeddy Wing2021-05-22 20:05:42 +0200
commitfdee5a8b0730921d072bfc700e120299c0f7bc79 (patch)
tree55718da404ae4d1d62638c6618b1c42fcc7c874a /src/main.rs
parent85f6e0a660439ca7ce0e42220fab9491d2d5a857 (diff)
downloadgoogle-calendar-rsvp-fdee5a8b0730921d072bfc700e120299c0f7bc79.tar.bz2
secret_from_file(): Remove `unwrap`s
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs16
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> {