Skip to content

Commit

Permalink
[bettereng] Remove a few expects
Browse files Browse the repository at this point in the history
  • Loading branch information
huitseeker authored and bors-libra committed Aug 26, 2020
1 parent d43a16d commit c71ca46
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 21 deletions.
4 changes: 3 additions & 1 deletion consensus/src/metrics_safety_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ impl MetricsSafetyRules {
let proofs = self
.storage
.retrieve_epoch_change_proof(sr_waypoint.version())
.expect("Unable to retrieve Waypoint state from Storage");
.map_err(|_| {
Error::InternalError("Unable to retrieve Waypoint state from storage".into())
})?;
self.initialize(&proofs)
}
}
Expand Down
12 changes: 6 additions & 6 deletions secure/storage/src/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,9 @@ impl CryptoStorage for VaultStorage {
) -> Result<Ed25519Signature, Error> {
let name = self.crypto_name(name);
let mut bytes = <T::Hasher as libra_crypto::hash::CryptoHasher>::seed().to_vec();
lcs::serialize_into(&mut bytes, &message)
.map_err(|_| libra_crypto::traits::CryptoMaterialError::SerializationError)
.expect("Serialization of signable material should not fail.");
lcs::serialize_into(&mut bytes, &message).map_err(|_| {
Error::InternalError("Serialization of signable material should not fail.".into())
})?;
Ok(self.client().sign_ed25519(&name, &bytes, None)?)
}

Expand All @@ -344,9 +344,9 @@ impl CryptoStorage for VaultStorage {
let name = self.crypto_name(name);
let vers = self.key_version(&name, &version)?;
let mut bytes = <T::Hasher as libra_crypto::hash::CryptoHasher>::seed().to_vec();
lcs::serialize_into(&mut bytes, &message)
.map_err(|_| libra_crypto::traits::CryptoMaterialError::SerializationError)
.expect("Serialization of signable material should not fail.");
lcs::serialize_into(&mut bytes, &message).map_err(|_| {
Error::InternalError("Serialization of signable material should not fail.".into())
})?;
Ok(self.client().sign_ed25519(&name, &bytes, Some(vers))?)
}
}
Expand Down
4 changes: 2 additions & 2 deletions storage/inspector/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#![forbid(unsafe_code)]

use anyhow::Result;
use anyhow::{anyhow, Result};
use libra_logger::info;
use libradb::LibraDB;
use std::path::PathBuf;
Expand Down Expand Up @@ -44,7 +44,7 @@ enum Command {
fn print_head(db: &LibraDB) -> Result<()> {
let si = db
.get_startup_info()
.expect("Can't get startup info")
.map_err(|_| anyhow!("Can't get startup info."))?
.expect("StartupInfo is empty, database is empty.");

let version = si.latest_ledger_info.ledger_info().version();
Expand Down
5 changes: 2 additions & 3 deletions testsuite/cli/libra-wallet/src/key_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! Private Keys adheres to [HKDF RFC 5869](https://tools.ietf.org/html/rfc5869).
use crate::mnemonic::Mnemonic;
use anyhow::Result;
use anyhow::{anyhow, Result};
use byteorder::{ByteOrder, LittleEndian};
use hmac::Hmac;
use libra_crypto::{
Expand Down Expand Up @@ -161,8 +161,7 @@ impl KeyFactory {

let hkdf_expand = Hkdf::<Sha3_256>::expand(&self.main(), Some(&info), 32)?;
let sk = Ed25519PrivateKey::try_from(hkdf_expand.as_slice())
.expect("Unable to convert into private key");

.map_err(|_| anyhow!("Unable to convert into private key"))?;
Ok(ExtendedPrivKey::new(child, sk))
}
}
Expand Down
5 changes: 3 additions & 2 deletions testsuite/cluster-test/src/aws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#![forbid(unsafe_code)]

use anyhow::{bail, format_err, Result};
use anyhow::{anyhow, bail, format_err, Result};
use libra_logger::{info, warn};
use rusoto_autoscaling::{
AutoScalingGroupNamesType, Autoscaling, AutoscalingClient, SetDesiredCapacityType,
Expand Down Expand Up @@ -36,7 +36,8 @@ pub async fn set_asg_size(
};
let credentials_provider = WebIdentityProvider::from_k8s_env();

let dispatcher = rusoto_core::HttpClient::new().expect("failed to create request dispatcher");
let dispatcher = rusoto_core::HttpClient::new()
.map_err(|_| anyhow!("Failed to create request dispatcher"))?;
let asc = AutoscalingClient::new_with(dispatcher, credentials_provider, Region::UsWest2);
libra_retrier::retry_async(libra_retrier::fixed_retry_strategy(10_000, 60), || {
let asc = asc.clone();
Expand Down
4 changes: 2 additions & 2 deletions testsuite/cluster-test/src/experiments/cpu_flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
time::Duration,
};

use anyhow::{format_err, Result};
use anyhow::{anyhow, format_err, Result};

use futures::{future::FutureExt, join};
use structopt::StructOpt;
Expand Down Expand Up @@ -66,7 +66,7 @@ impl Experiment for CpuFlamegraph {
.tx_emitter
.emit_txn_for(tx_emitter_duration, emit_job_request)
.boxed();
let run_id = env::var("RUN_ID").expect("RUN_ID is not set");
let run_id = env::var("RUN_ID").map_err(|_| anyhow!("RUN_ID is not set"))?;
let filename = "libra-node-perf.svg";
let command = generate_perf_flamegraph_command(&filename, &run_id, self.duration_secs);
let flame_graph = self.perf_instance.util_cmd(command, "generate-flamegraph");
Expand Down
6 changes: 4 additions & 2 deletions testsuite/cluster-test/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#![forbid(unsafe_code)]

use anyhow::{format_err, Result};
use anyhow::{anyhow, format_err, Result};
use reqwest::{header::USER_AGENT, Url};
use serde::Deserialize;

Expand Down Expand Up @@ -40,7 +40,9 @@ impl GitHub {
/// Paging is not implemented yet
pub fn get_commits(&self, repo: &str, sha: &str) -> Result<Vec<CommitInfo>> {
let url = format!("https://api.github.com/repos/{}/commits?sha={}", repo, sha);
let url: Url = url.parse().expect("Failed to parse github url");
let url: Url = url
.parse()
.map_err(|_| anyhow!("Failed to parse github url"))?;
let request = self.client.get(url);
let response = request
.header(USER_AGENT, "libra-cluster-test")
Expand Down
5 changes: 2 additions & 3 deletions testsuite/cluster-test/src/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#![forbid(unsafe_code)]

use anyhow::{bail, format_err, Result};
use anyhow::{anyhow, bail, format_err, Result};
use reqwest::Url;
use serde::Deserialize;
use std::{collections::HashMap, time::Duration};
Expand Down Expand Up @@ -64,8 +64,7 @@ impl Prometheus {
end.as_secs(),
step
))
.expect("Failed to make query_range url");

.map_err(|_| anyhow!("Failed to make query range url"))?;
let response = self
.client
.get(url.clone())
Expand Down

0 comments on commit c71ca46

Please sign in to comment.