fix: improve error messages
This commit is contained in:
+1
-1
@@ -78,7 +78,7 @@ async fn get_output_path(
|
||||
raw_config.output.path.clone()
|
||||
};
|
||||
tokio::fs::create_dir_all(&output_path).await.wrap_err_with(|| {
|
||||
format!("failed to create output directory: {}", output_path.display())
|
||||
format!("failed to create directory: {}", output_path.display())
|
||||
})?;
|
||||
Ok(output_path)
|
||||
}
|
||||
|
||||
+6
-6
@@ -61,11 +61,11 @@ impl DbType {
|
||||
let db_path = self.db_path().await?;
|
||||
let mut file =
|
||||
tokio::fs::File::create(&db_path).await.wrap_err_with(|| {
|
||||
format!("failed to create file {}", db_path.display())
|
||||
format!("failed to create file: {}", db_path.display())
|
||||
})?;
|
||||
while let Some(chunk) = response.chunk().await? {
|
||||
file.write_all(&chunk).await.wrap_err_with(|| {
|
||||
format!("failed to write to file {}", db_path.display())
|
||||
format!("failed to write to file: {}", db_path.display())
|
||||
})?;
|
||||
#[cfg(feature = "tui")]
|
||||
drop(
|
||||
@@ -81,7 +81,7 @@ impl DbType {
|
||||
async fn save_etag(self, etag: impl AsRef<[u8]>) -> crate::Result<()> {
|
||||
let path = self.etag_path().await?;
|
||||
tokio::fs::write(&path, etag).await.wrap_err_with(move || {
|
||||
format!("failed to write to file {}", path.display())
|
||||
format!("failed to write to file: {}", path.display())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ impl DbType {
|
||||
Ok(text) => Ok(text.parse().ok()),
|
||||
Err(e) if e.kind() == io::ErrorKind::NotFound => Ok(None),
|
||||
Err(e) => Err(e).wrap_err_with(move || {
|
||||
format!("failed to read file {} to string", path.display())
|
||||
format!("failed to read file to string: {}", path.display())
|
||||
}),
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@ impl DbType {
|
||||
Ok(()) => Ok(()),
|
||||
Err(e) if e.kind() == io::ErrorKind::NotFound => Ok(()),
|
||||
Err(e) => Err(e).wrap_err_with(move || {
|
||||
format!("failed to remove {}", path.display())
|
||||
format!("failed to remove file: {}", path.display())
|
||||
}),
|
||||
}
|
||||
}
|
||||
@@ -185,7 +185,7 @@ impl DbType {
|
||||
tokio::task::spawn_blocking(move || maxminddb::Reader::open_mmap(path))
|
||||
.await?
|
||||
.wrap_err_with(move || {
|
||||
format!("failed to open {} database", self.name())
|
||||
format!("failed to open IP database: {}", self.name())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
+5
-10
@@ -138,7 +138,7 @@ pub async fn save_proxies(
|
||||
Ok(()) => Ok(()),
|
||||
Err(e) if e.kind() == io::ErrorKind::NotFound => Ok(()),
|
||||
Err(e) => Err(e).wrap_err_with(|| {
|
||||
format!("failed to remove file {}", path.display())
|
||||
format!("failed to remove file: {}", path.display())
|
||||
}),
|
||||
}?;
|
||||
let json_data = if pretty {
|
||||
@@ -147,9 +147,7 @@ pub async fn save_proxies(
|
||||
serde_json::to_vec(&proxy_dicts)?
|
||||
};
|
||||
tokio::fs::write(&path, json_data).await.wrap_err_with(
|
||||
move || {
|
||||
format!("failed to write proxies to {}", path.display())
|
||||
},
|
||||
move || format!("failed to write to file: {}", path.display()),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
@@ -162,7 +160,7 @@ pub async fn save_proxies(
|
||||
Err(e) if e.kind() == io::ErrorKind::NotFound => Ok(()),
|
||||
Err(e) => Err(e).wrap_err_with(|| {
|
||||
format!(
|
||||
"failed to remove directory {}",
|
||||
"failed to remove directory: {}",
|
||||
directory_path.display()
|
||||
)
|
||||
}),
|
||||
@@ -181,7 +179,7 @@ pub async fn save_proxies(
|
||||
.await
|
||||
.wrap_err_with(|| {
|
||||
format!(
|
||||
"failed to write proxies to {}",
|
||||
"failed to write to file: {}",
|
||||
directory_path.join("all.txt").display()
|
||||
)
|
||||
})?;
|
||||
@@ -192,10 +190,7 @@ pub async fn save_proxies(
|
||||
file_path.set_extension("txt");
|
||||
tokio::fs::write(&file_path, text).await.wrap_err_with(
|
||||
move || {
|
||||
format!(
|
||||
"failed to write proxies to {}",
|
||||
file_path.display()
|
||||
)
|
||||
format!("failed to write to file: {}", file_path.display())
|
||||
},
|
||||
)?;
|
||||
}
|
||||
|
||||
+2
-2
@@ -182,9 +182,9 @@ pub fn get_config_path() -> String {
|
||||
pub async fn read_config(path: &Path) -> crate::Result<RawConfig> {
|
||||
let raw_config =
|
||||
tokio::fs::read_to_string(path).await.wrap_err_with(move || {
|
||||
format!("failed to read {} to string", path.display())
|
||||
format!("failed to read file to string: {}", path.display())
|
||||
})?;
|
||||
toml::from_str(&raw_config).wrap_err_with(move || {
|
||||
format!("failed to parse {} as TOML config file", path.display())
|
||||
format!("failed to parse TOML config file: {}", path.display())
|
||||
})
|
||||
}
|
||||
|
||||
+14
-5
@@ -1,6 +1,6 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use color_eyre::eyre::OptionExt as _;
|
||||
use color_eyre::eyre::{OptionExt as _, WrapErr as _};
|
||||
use foldhash::HashSetExt as _;
|
||||
|
||||
#[cfg(feature = "tui")]
|
||||
@@ -46,15 +46,24 @@ async fn scrape_one(
|
||||
_ => {
|
||||
drop(http_client);
|
||||
match u.to_file_path() {
|
||||
Ok(path) => tokio::fs::read_to_string(path).await,
|
||||
Err(()) => tokio::fs::read_to_string(&source.url).await,
|
||||
Ok(path) => tokio::fs::read_to_string(path)
|
||||
.await
|
||||
.wrap_err_with(move || {
|
||||
format!("failed to read file to string: {u}")
|
||||
}),
|
||||
Err(()) => tokio::fs::read_to_string(&source.url)
|
||||
.await
|
||||
.wrap_err_with(move || {
|
||||
format!("failed to read file to string: {u}")
|
||||
}),
|
||||
}
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
drop(http_client);
|
||||
tokio::fs::read_to_string(&source.url).await.map_err(Into::into)
|
||||
tokio::fs::read_to_string(&source.url).await.wrap_err_with(|| {
|
||||
format!("failed to read file to string: {}", source.url)
|
||||
})
|
||||
};
|
||||
|
||||
#[cfg(feature = "tui")]
|
||||
|
||||
Reference in New Issue
Block a user