Forráskód Böngészése

Handle more errors

Vecna 9 hónapja
szülő
commit
2e94b4df34
1 módosított fájl, 14 hozzáadás és 2 törlés
  1. 14 2
      src/lib.rs

+ 14 - 2
src/lib.rs

@@ -8,6 +8,7 @@ use lox_library::{
     scalar_u32, IssuerPubKey, OPENINV_LENGTH,
 };
 use lox_utils::{EncBridgeTable, Invite};
+use serde::de::Error as SerdeError;
 use serde_json::error::Error;
 use std::collections::HashMap;
 
@@ -115,7 +116,10 @@ pub async fn get_bucket(
     let (id, key) = from_scalar(lox_cred.bucket).unwrap();
     let encbucket = match encbuckets.get(&id) {
         Some(encbucket) => encbucket,
-        None => panic!("Provided ID not found"),
+        None => {
+            // This is probably an abuse of the serde_json Error struct.
+            return Err(Error::missing_field("Provided ID not found"));
+        }
     };
     Ok(BridgeTable::decrypt_bucket(id, &key, &encbucket).unwrap())
 }
@@ -210,7 +214,15 @@ pub async fn issue_invite(
 
     let (id, key) = from_scalar(lox_cred.bucket).unwrap();
     let bucket = BridgeTable::decrypt_bucket(id, &key, &encbuckets.get(&id).unwrap()).unwrap();
-    let reachcred = bucket.1.unwrap();
+    let reachcred = match bucket.1 {
+        Some(v) => v,
+        None => {
+            // This is probably an abuse of the serde_json Error struct.
+            return Err(Error::missing_field(
+                "Expected reachability credential but none was found",
+            ));
+        }
+    };
 
     let (req, state) = issue_invite::request(
         lox_cred,