mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-16 07:52:06 +08:00
fix(logging): include paths in file failure logs
This commit is contained in:
@@ -1351,8 +1351,9 @@ async fn sync_runtime_providers_by_service() -> Result<ProviderSync> {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Service,
|
||||
"provider cache {} was not read: {error:#}",
|
||||
declared.provider.destination
|
||||
"failed to read provider cache {} into {}: {error:#}",
|
||||
declared.provider.destination,
|
||||
temp.display()
|
||||
);
|
||||
outcome.pending += 1;
|
||||
remove_temp(&temp).await;
|
||||
@@ -1442,8 +1443,9 @@ async fn publish_fetched(
|
||||
logging!(
|
||||
warn,
|
||||
Type::Service,
|
||||
"provider cache {} was not published: {error}",
|
||||
cache.declared.provider.destination
|
||||
"failed to rename provider cache {} to {}: {error}",
|
||||
cache.temp.display(),
|
||||
target.display()
|
||||
);
|
||||
remove_temp(&cache.temp).await;
|
||||
}
|
||||
@@ -1587,7 +1589,9 @@ fn has_settled(mtime_ns: Option<u64>) -> bool {
|
||||
// Exclusive creation protects existing files from truncation and cleanup.
|
||||
async fn create_sync_temp(target: &Path) -> Result<(PathBuf, tokio::fs::File)> {
|
||||
if let Some(parent) = target.parent() {
|
||||
tokio::fs::create_dir_all(parent).await?;
|
||||
tokio::fs::create_dir_all(parent)
|
||||
.await
|
||||
.with_context(|| format!("failed to create provider cache directory {}", parent.display()))?;
|
||||
}
|
||||
let name = target
|
||||
.file_name()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{config::Config, singleton, utils::dirs};
|
||||
use anyhow::Result;
|
||||
use anyhow::{Context as _, Result};
|
||||
use chrono::Utc;
|
||||
use clash_verge_logging::{Type, logging};
|
||||
use parking_lot::RwLock;
|
||||
@@ -47,17 +47,20 @@ impl SilentUpdater {
|
||||
|
||||
fn write_cache(bytes: &[u8], version: &str) -> Result<()> {
|
||||
let cache_dir = Self::cache_dir()?;
|
||||
std::fs::create_dir_all(&cache_dir)?;
|
||||
std::fs::create_dir_all(&cache_dir)
|
||||
.with_context(|| format!("failed to create update cache directory {}", cache_dir.display()))?;
|
||||
|
||||
let bin_path = cache_dir.join("pending_update.bin");
|
||||
std::fs::write(&bin_path, bytes)?;
|
||||
std::fs::write(&bin_path, bytes)
|
||||
.with_context(|| format!("failed to write update cache {}", bin_path.display()))?;
|
||||
|
||||
let meta = UpdateCacheMeta {
|
||||
version: version.to_string(),
|
||||
downloaded_at: Utc::now().to_rfc3339(),
|
||||
};
|
||||
let meta_path = cache_dir.join("pending_update.json");
|
||||
std::fs::write(&meta_path, serde_json::to_string_pretty(&meta)?)?;
|
||||
std::fs::write(&meta_path, serde_json::to_string_pretty(&meta)?)
|
||||
.with_context(|| format!("failed to write update metadata {}", meta_path.display()))?;
|
||||
|
||||
logging!(
|
||||
info,
|
||||
@@ -71,7 +74,7 @@ impl SilentUpdater {
|
||||
|
||||
fn read_cache_bytes() -> Result<Vec<u8>> {
|
||||
let bin_path = Self::cache_dir()?.join("pending_update.bin");
|
||||
Ok(std::fs::read(bin_path)?)
|
||||
std::fs::read(&bin_path).with_context(|| format!("failed to read update cache {}", bin_path.display()))
|
||||
}
|
||||
|
||||
fn read_cache_meta() -> Result<UpdateCacheMeta> {
|
||||
@@ -85,7 +88,12 @@ impl SilentUpdater {
|
||||
&& cache_dir.exists()
|
||||
{
|
||||
if let Err(e) = std::fs::remove_dir_all(&cache_dir) {
|
||||
logging!(warn, Type::System, "Failed to delete update cache: {e}");
|
||||
logging!(
|
||||
warn,
|
||||
Type::System,
|
||||
"Failed to delete update cache {}: {e}",
|
||||
cache_dir.display()
|
||||
);
|
||||
} else {
|
||||
logging!(info, Type::System, "Update cache deleted");
|
||||
}
|
||||
@@ -176,7 +184,7 @@ impl SilentUpdater {
|
||||
logging!(
|
||||
warn,
|
||||
Type::System,
|
||||
"Failed to read cached update bytes: {e}, cleaning up"
|
||||
"Failed to read cached update bytes: {e:#}, cleaning up"
|
||||
);
|
||||
Self::delete_cache();
|
||||
return false;
|
||||
@@ -456,7 +464,7 @@ impl SilentUpdater {
|
||||
.await?;
|
||||
|
||||
if let Err(e) = Self::write_cache(&bytes, &version) {
|
||||
logging!(warn, Type::System, "Silent updater: failed to write cache: {e}");
|
||||
logging!(warn, Type::System, "Silent updater: failed to write cache: {e:#}");
|
||||
}
|
||||
|
||||
*self.pending_bytes.write() = Some(bytes);
|
||||
|
||||
@@ -226,7 +226,7 @@ impl CoreConfigValidator {
|
||||
Ok(content) => content,
|
||||
Err(err) => {
|
||||
let error_msg: String = format!("Failed to read file: {err}").into();
|
||||
logging!(error, Type::Validate, "无法读取文件: {}", error_msg);
|
||||
logging!(error, Type::Validate, "Failed to read file {config_path}: {err}");
|
||||
return Ok(ValidationOutcome::invalid_from_message(error_msg));
|
||||
}
|
||||
};
|
||||
@@ -238,7 +238,7 @@ impl CoreConfigValidator {
|
||||
}
|
||||
Err(err) => {
|
||||
let error_msg: String = format!("YAML syntax error: {err}").into();
|
||||
logging!(error, Type::Validate, "YAML语法错误: {}", error_msg);
|
||||
logging!(error, Type::Validate, "YAML syntax error in {config_path}: {err}");
|
||||
Ok(ValidationOutcome::invalid_from_message(error_msg))
|
||||
}
|
||||
}
|
||||
@@ -249,7 +249,7 @@ impl CoreConfigValidator {
|
||||
Ok(content) => content,
|
||||
Err(err) => {
|
||||
let error_msg: String = format!("Failed to read script file: {err}").into();
|
||||
logging!(warn, Type::Validate, "脚本语法错误: {}", err);
|
||||
logging!(warn, Type::Validate, "Failed to read script file {path}: {err}");
|
||||
return Ok(ValidationOutcome::invalid_from_message(error_msg));
|
||||
}
|
||||
};
|
||||
@@ -291,7 +291,7 @@ impl CoreConfigValidator {
|
||||
}
|
||||
Err(err) => {
|
||||
let error_msg: String = format!("Script syntax error: {err}").into();
|
||||
logging!(warn, Type::Validate, "脚本语法错误: {}", err);
|
||||
logging!(warn, Type::Validate, "Script syntax error in {path}: {err}");
|
||||
Ok(ValidationOutcome::invalid_from_message(error_msg))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user