mirror of
https://github.com/esp-rs/espup.git
synced 2025-10-02 15:14:56 +00:00
refactor: ♻️ Refactor toolchain/mod.rs errors
This commit is contained in:
parent
ff16280965
commit
a443f848bd
13
src/error.rs
13
src/error.rs
@ -1,6 +1,6 @@
|
||||
use crate::emoji;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, miette::Diagnostic, thiserror::Error)]
|
||||
#[derive(Debug, miette::Diagnostic, thiserror::Error)]
|
||||
pub enum Error {
|
||||
// Host Triple
|
||||
#[diagnostic(code(espup::host_triple::unsupported_host_triple))]
|
||||
@ -26,4 +26,15 @@ pub enum Error {
|
||||
#[diagnostic(code(espup::config::failed_to_write))]
|
||||
#[error("{} Failed to write config to '{0}'", emoji::ERROR)]
|
||||
FailedToWrite(String),
|
||||
// Toolchain
|
||||
#[error(transparent)]
|
||||
IoError(#[from] std::io::Error),
|
||||
#[error(transparent)]
|
||||
RewquestError(#[from] reqwest::Error),
|
||||
#[diagnostic(code(espup::toolchain::failed_to_create_directory))]
|
||||
#[error("{} Creating directory '{0}' failed", emoji::ERROR)]
|
||||
FailedToCreateDirectory(String),
|
||||
#[diagnostic(code(espup::toolchain::unsupported_file_extension))]
|
||||
#[error("{} Unsuported file extension: '{0}'", emoji::ERROR)]
|
||||
UnsuportedFileExtension(String),
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::emoji;
|
||||
use anyhow::{bail, Result};
|
||||
use crate::{emoji, error::Error};
|
||||
use anyhow::Result;
|
||||
use dirs::home_dir;
|
||||
use flate2::bufread::GzDecoder;
|
||||
use log::info;
|
||||
@ -27,7 +27,7 @@ pub fn download_file(
|
||||
file_name: &str,
|
||||
output_directory: &str,
|
||||
uncompress: bool,
|
||||
) -> Result<String> {
|
||||
) -> Result<String, Error> {
|
||||
let file_path = format!("{}/{}", output_directory, file_name);
|
||||
if Path::new(&file_path).exists() {
|
||||
info!("{} Using cached file: '{}'", emoji::INFO, file_path);
|
||||
@ -39,11 +39,7 @@ pub fn download_file(
|
||||
output_directory
|
||||
);
|
||||
if let Err(_e) = create_dir_all(output_directory) {
|
||||
bail!(
|
||||
"{} Creating directory '{}' failed",
|
||||
emoji::ERROR,
|
||||
output_directory
|
||||
);
|
||||
return Err(Error::FailedToCreateDirectory(output_directory.to_string()));
|
||||
}
|
||||
}
|
||||
info!(
|
||||
@ -86,11 +82,7 @@ pub fn download_file(
|
||||
archive.unpack(output_directory).unwrap();
|
||||
}
|
||||
_ => {
|
||||
bail!(
|
||||
"{} Unsuported file extension: '{}'",
|
||||
emoji::ERROR,
|
||||
extension
|
||||
);
|
||||
return Err(Error::UnsuportedFileExtension(extension.to_string()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user