Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade SNAFU to 0.7 #115

Merged
merged 1 commit into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ rusoto_credential = "0.47.0"
rusoto_ebs = { version = "0.47.0", default-features = false }
rusoto_ec2 = { version = "0.47.0", default-features = false }
rusoto_signature = "0.47.0"
snafu = "0.6.9"
snafu = "0.7"
indicatif = "0.16.2"
tempfile = "3.1.0"
async-trait = "0.1.50"
6 changes: 3 additions & 3 deletions src/bin/coldsnap/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ this should cover most scenarios.
/// Create a rusoto client of the given type using the (optional) given region, endpoint, and credentials.
macro_rules! build_client {
($client_type:ty, $region_name:expr, $endpoint:expr, $profile:expr) => {{
let http_client = HttpClient::new().context(error::CreateHttpClient)?;
let http_client = HttpClient::new().context(error::CreateHttpClientSnafu)?;
let profile_provider = match $profile {
Some(profile) => {
let mut p = ProfileProvider::new().context(error::CreateProfileProvider)?;
let mut p = ProfileProvider::new().context(error::CreateProfileProviderSnafu)?;
p.set_profile(profile);
Some(p)
}
Expand All @@ -23,7 +23,7 @@ macro_rules! build_client {

fn parse_region(region: Option<String>) -> Result<Option<Region>> {
region
.map(|r| r.parse().context(error::ParseRegion { region: r }))
.map(|r| r.parse().context(error::ParseRegionSnafu { region: r }))
.transpose()
}

Expand Down
14 changes: 7 additions & 7 deletions src/bin/coldsnap/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ async fn run() -> Result<()> {
let downloader = SnapshotDownloader::new(client);
ensure!(
download_args.file.file_name().is_some(),
error::ValidateFilename {
error::ValidateFilenameSnafu {
path: download_args.file
}
);
ensure!(
download_args.force || !download_args.file.exists(),
error::FileExists {
error::FileExistsSnafu {
path: download_args.file
}
);
Expand All @@ -60,7 +60,7 @@ async fn run() -> Result<()> {
progress_bar,
)
.await
.context(error::DownloadSnapshot)?;
.context(error::DownloadSnapshotSnafu)?;
}

SubCommand::Upload(upload_args) => {
Expand All @@ -80,15 +80,15 @@ async fn run() -> Result<()> {
progress_bar,
)
.await
.context(error::UploadSnapshot)?;
.context(error::UploadSnapshotSnafu)?;
println!("{}", snapshot_id);
if upload_args.wait {
let client = build_client!(Ec2Client, args.region, args.endpoint, args.profile)?;
let waiter = SnapshotWaiter::new(client);
waiter
.wait_for_completed(&snapshot_id)
.await
.context(error::WaitSnapshot)?;
.context(error::WaitSnapshotSnafu)?;
}
}

Expand All @@ -104,7 +104,7 @@ async fn run() -> Result<()> {
waiter
.wait(wait_args.snapshot_id, wait_params)
.await
.context(error::WaitSnapshot)?;
.context(error::WaitSnapshotSnafu)?;
}
}
Ok(())
Expand Down Expand Up @@ -232,7 +232,7 @@ mod error {
use snafu::Snafu;

#[derive(Debug, Snafu)]
#[snafu(visibility = "pub(super)")]
#[snafu(visibility(pub(super)))]
pub(super) enum Error {
#[snafu(display("Failed to create HTTP client: {}", source))]
CreateHttpClient {
Expand Down
10 changes: 5 additions & 5 deletions src/block_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ pub(crate) fn get_block_device_size(path: &Path) -> Result<i64> {
let file = OpenOptions::new()
.read(true)
.open(path)
.context(error::OpenFile { path })?;
.context(error::OpenFileSnafu { path })?;

let mut block_device_size = 0;
let result = unsafe { ioctl::blkgetsize64(file.as_raw_fd(), &mut block_device_size) }
.context(error::GetBlockDeviceSize { path })?;
ensure!(result == 0, error::InvalidBlockDeviceSize { result });
.context(error::GetBlockDeviceSizeSnafu { path })?;
ensure!(result == 0, error::InvalidBlockDeviceSizeSnafu { result });

let block_device_size =
i64::try_from(block_device_size).with_context(|| error::ConvertNumber {
i64::try_from(block_device_size).with_context(|_| error::ConvertNumberSnafu {
what: "block device size",
number: block_device_size.to_string(),
target: "i64",
Expand All @@ -48,7 +48,7 @@ mod error {
use std::path::PathBuf;

#[derive(Debug, Snafu)]
#[snafu(visibility = "pub(super)")]
#[snafu(visibility(pub(super)))]
pub(super) enum Error {
#[snafu(display("Failed to open '{}': {}", path.display(), source))]
OpenFile {
Expand Down
Loading