Created
November 27, 2019 00:06
-
-
Save vmx/108a99d3c9c08c2cb819b620a736c74d to your computer and use it in GitHub Desktop.
From `failure` to `anyhow`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://github.com/filecoin-project/rust-fil-proofs/pull/956/files/4fd1396deb3172d824d97682f4366bfa9abacc09#diff-301ba6b17c22cbd0c1d0ecb79a8104be | |
let meta = serde_json::from_reader(file).map_err(FailureError::from)?; | |
-> | |
let meta = serde_json::from_reader(file)?; | |
.ok_or_else(|| format_err!("could not map filename to parameter id"))?; | |
-> | |
.context("could not map filename to parameter id")?; | |
Err(format_err!("cannot pre-commit a sector (id = {:?}) which is not fully packed (remaining space = {:?})", | |
-> | |
Err(anyhow!("cannot pre-commit a sector (id = {:?}) which is not fully packed (remaining space = {:?})", | |
if parameter_file_path.exists() { | |
rename(parameter_file_path, target_parameter_file_path)?; | |
Ok(()) | |
} else { | |
Err(err_msg(ERROR_PARAMETER_FILE)) | |
} | |
-> | |
ensure!(parameter_file_path.exists(), ERROR_PARAMETER_FILE); | |
rename(parameter_file_path, target_parameter_file_path)?; | |
Ok(()) | |
if bytes.len() != 32 { | |
return Err(Error::BadFrBytes); | |
} | |
-> | |
ensure!(bytes.len() == 32, Error::BadFrBytes); | |
return Err(err_msg(format!( | |
"JSON file '{}' does not exist", | |
&json_path.to_str().unwrap_or("") | |
))); | |
-> | |
bail!( | |
"JSON file '{}' does not exist", | |
&json_path.to_str().unwrap_or("") | |
); | |
serde_json::from_reader(reader).map_err(|err| { | |
failure::format_err!( | |
"JSON file '{}' did not parse correctly: {}", | |
&json_path.to_str().unwrap_or(""), | |
err, | |
) | |
})? | |
-> | |
serde_json::from_reader(reader).with_context(|| { | |
format!( | |
"JSON file '{}' did not parse correctly", | |
&json_path.to_str().unwrap_or(""), | |
) | |
})? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment