mirror of
https://github.com/esp-rs/espup.git
synced 2025-10-03 15:44:45 +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;
|
use crate::emoji;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, miette::Diagnostic, thiserror::Error)]
|
#[derive(Debug, miette::Diagnostic, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
// Host Triple
|
// Host Triple
|
||||||
#[diagnostic(code(espup::host_triple::unsupported_host_triple))]
|
#[diagnostic(code(espup::host_triple::unsupported_host_triple))]
|
||||||
@ -26,4 +26,15 @@ pub enum Error {
|
|||||||
#[diagnostic(code(espup::config::failed_to_write))]
|
#[diagnostic(code(espup::config::failed_to_write))]
|
||||||
#[error("{} Failed to write config to '{0}'", emoji::ERROR)]
|
#[error("{} Failed to write config to '{0}'", emoji::ERROR)]
|
||||||
FailedToWrite(String),
|
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 crate::{emoji, error::Error};
|
||||||
use anyhow::{bail, Result};
|
use anyhow::Result;
|
||||||
use dirs::home_dir;
|
use dirs::home_dir;
|
||||||
use flate2::bufread::GzDecoder;
|
use flate2::bufread::GzDecoder;
|
||||||
use log::info;
|
use log::info;
|
||||||
@ -27,7 +27,7 @@ pub fn download_file(
|
|||||||
file_name: &str,
|
file_name: &str,
|
||||||
output_directory: &str,
|
output_directory: &str,
|
||||||
uncompress: bool,
|
uncompress: bool,
|
||||||
) -> Result<String> {
|
) -> Result<String, Error> {
|
||||||
let file_path = format!("{}/{}", output_directory, file_name);
|
let file_path = format!("{}/{}", output_directory, file_name);
|
||||||
if Path::new(&file_path).exists() {
|
if Path::new(&file_path).exists() {
|
||||||
info!("{} Using cached file: '{}'", emoji::INFO, file_path);
|
info!("{} Using cached file: '{}'", emoji::INFO, file_path);
|
||||||
@ -39,11 +39,7 @@ pub fn download_file(
|
|||||||
output_directory
|
output_directory
|
||||||
);
|
);
|
||||||
if let Err(_e) = create_dir_all(output_directory) {
|
if let Err(_e) = create_dir_all(output_directory) {
|
||||||
bail!(
|
return Err(Error::FailedToCreateDirectory(output_directory.to_string()));
|
||||||
"{} Creating directory '{}' failed",
|
|
||||||
emoji::ERROR,
|
|
||||||
output_directory
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
info!(
|
info!(
|
||||||
@ -86,11 +82,7 @@ pub fn download_file(
|
|||||||
archive.unpack(output_directory).unwrap();
|
archive.unpack(output_directory).unwrap();
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
bail!(
|
return Err(Error::UnsuportedFileExtension(extension.to_string()));
|
||||||
"{} Unsuported file extension: '{}'",
|
|
||||||
emoji::ERROR,
|
|
||||||
extension
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user