aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2021-05-22 19:52:26 +0200
committerTeddy Wing2021-05-22 19:52:26 +0200
commit79f53af864312e4171aaa047a7dabd46375b2987 (patch)
tree93406d893bd2c4b5c410db2da164648d46eae293 /src
parent5562492d935d55e5e707cae4a80002733c54eb5c (diff)
downloadgoogle-calendar-rsvp-79f53af864312e4171aaa047a7dabd46375b2987.tar.bz2
event_id_from_base64(): Return a `Result`
Diffstat (limited to 'src')
-rw-r--r--src/main.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index 1a8316d..8428b90 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -108,7 +108,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
for event_id in &event_ids {
let event = rsvp(
- &event_id_from_base64(event_id),
+ &event_id_from_base64(event_id)?,
&action,
).await;
@@ -189,16 +189,20 @@ fn secret_from_file() -> oauth2::ApplicationSecret {
}
}
-fn event_id_from_base64(event_id: &str) -> String {
+fn event_id_from_base64(event_id: &str) -> anyhow::Result<String> {
let decoded = match base64::decode(event_id) {
Ok(d) => d,
- Err(_) => return event_id.to_owned(),
+ Err(_) => return Ok(event_id.to_owned()),
};
- let id_email_pair = str::from_utf8(&decoded).unwrap();
+ let id_email_pair = str::from_utf8(&decoded)?;
let values = id_email_pair.split(" ").collect::<Vec<_>>();
- let id = values.first().unwrap().to_string();
+ let id = values.first()
+ .ok_or(
+ anyhow::anyhow!("unable to extract event ID from '{}'", id_email_pair),
+ )?
+ .to_string();
- id
+ Ok(id)
}
fn eid_from_email(email: &[u8]) -> String {