Ver código fonte

add better error messages for missing env vars

Pietro Albini 6 anos atrás
pai
commit
158b80d29c
2 arquivos alterados com 10 adições e 2 exclusões
  1. 4 1
      src/main.rs
  2. 6 1
      src/payload.rs

+ 4 - 1
src/main.rs

@@ -110,7 +110,10 @@ fn not_found(_: &Request) -> &'static str {
 fn main() {
     dotenv::dotenv().ok();
     let client = Client::new();
-    let gh = GithubClient::new(client.clone(), env::var("GITHUB_API_TOKEN").unwrap());
+    let gh = GithubClient::new(
+        client.clone(),
+        env::var("GITHUB_API_TOKEN").expect("Missing GITHUB_API_TOKEN"),
+    );
     let username = Arc::new(User::current(&gh).unwrap().login);
     let mut registry = HandleRegistry::new();
     handlers::register_all(&mut registry, gh.clone(), username);

+ 6 - 1
src/payload.rs

@@ -46,7 +46,12 @@ impl FromDataSimple for SignedPayload {
             ));
         }
 
-        let key = PKey::hmac(env::var("GITHUB_WEBHOOK_SECRET").unwrap().as_bytes()).unwrap();
+        let key = PKey::hmac(
+            env::var("GITHUB_WEBHOOK_SECRET")
+                .expect("Missing GITHUB_WEBHOOK_SECRET")
+                .as_bytes(),
+        )
+        .unwrap();
         let mut signer = Signer::new(MessageDigest::sha1(), &key).unwrap();
         signer.update(&buf).unwrap();
         let hmac = signer.sign_to_vec().unwrap();