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

Print more informative errors than generic os error #11

Merged
merged 2 commits into from
Apr 11, 2024
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
2 changes: 1 addition & 1 deletion 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
@@ -1,6 +1,6 @@
[package]
name = "quicksync"
version = "0.1.10"
version = "0.1.11"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
14 changes: 13 additions & 1 deletion src/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,19 @@ pub fn download_checksum(url: Url) -> Result<String> {
}

pub fn calculate_checksum(file_path: &Path) -> Result<String> {
let file = File::open(file_path)?;
let file = match File::open(file_path) {
Ok(file) => file,
Err(error) => match error.kind() {
std::io::ErrorKind::NotFound => {
anyhow::bail!(
"Cannot calculate checksum: File not found at {}",
file_path.display()
)
}
_ => anyhow::bail!("Cannot calculate checksum: Error opening file: {}", error),
},
};

let mut reader = BufReader::with_capacity(16 * 1024 * 1024, file);
let mut hasher = md5::Context::new();

Expand Down
12 changes: 10 additions & 2 deletions src/go_spacemesh.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
use anyhow::Result;
use std::process::Command;
use std::{io::ErrorKind, process::Command};

use crate::utils::trim_version;

pub fn get_version(path: &str) -> Result<String> {
let output = Command::new(path).arg("version").output()?;
let output = Command::new(path)
.arg("version")
.output()
.map_err(|error| match error.kind() {
ErrorKind::NotFound => {
anyhow::anyhow!("Executable not found at path: {}", path)
}
other_error => panic!("Unexpected error: {:?}", other_error),
})?;

let version = String::from_utf8(output.stdout)?;
let trimmed = trim_version(version.trim()).to_string();
Expand Down
14 changes: 10 additions & 4 deletions src/unpack.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::Result;
use anyhow::{Context, Result};
use std::fs::File;
use std::io::{BufReader, BufWriter, Error};
use std::path::Path;
Expand Down Expand Up @@ -32,16 +32,22 @@ fn find_file_in_archive<'a>(
}

pub fn unpack_zstd(archive_path: &Path, output_path: &Path) -> Result<()> {
let file = File::open(archive_path)?;
let file = File::open(archive_path).context(format!(
"Failed to open archive at path: {:?}",
archive_path
))?;
let reader = BufReader::new(file);
let mut decoder = Decoder::new(reader)?;

decoder.window_log_max(31)?;
let outpath = Path::new(output_path);
if let Some(p) = outpath.parent() {
std::fs::create_dir_all(p)?;
std::fs::create_dir_all(p).context(format!("Failed to create directory at path: {:?}", p))?;
}
let outfile = File::create(outpath)?;
let outfile = File::create(outpath).context(format!(
"Failed to create output file at path: {:?}",
outpath
))?;
let mut writer = BufWriter::new(outfile);

let mut reader = ReaderWithBytes::new(decoder);
Expand Down
Loading