Write paths in logs as escaped ASCII text

This commit is contained in:
Oliver Hamlet
2025-04-28 20:40:37 +01:00
parent 3ee1789316
commit 0fb4624e58
4 changed files with 23 additions and 21 deletions
+4 -3
View File
@@ -8,6 +8,7 @@ use std::{
use super::error::{ArchiveParsingError, ArchivePathParsingError};
use crate::{
archive::error::slice_too_small,
escape_ascii,
logging::{self, format_details},
plugin::has_ascii_extension,
};
@@ -20,7 +21,7 @@ pub fn assets_in_archives(archive_paths: &[PathBuf]) -> BTreeMap<u64, BTreeSet<u
for archive_path in archive_paths {
logging::trace!(
"Getting assets loaded from the Bethesda archive at \"{}\"",
archive_path.display()
escape_ascii(archive_path)
);
let assets = match get_assets_in_archive(archive_path) {
@@ -28,7 +29,7 @@ pub fn assets_in_archives(archive_paths: &[PathBuf]) -> BTreeMap<u64, BTreeSet<u
Err(e) => {
logging::error!(
"Encountered an error while trying to read the Bethesda archive at \"{}\": {}",
archive_path.display(),
escape_ascii(archive_path),
format_details(&e)
);
continue;
@@ -46,7 +47,7 @@ pub fn assets_in_archives(archive_paths: &[PathBuf]) -> BTreeMap<u64, BTreeSet<u
"The folder and file with hashes {:x} and {:x} in \"{}\" are present in another Bethesda archive.",
folder_hash,
file_hash,
archive_path.display()
escape_ascii(archive_path)
);
}
}
+9 -8
View File
@@ -15,6 +15,7 @@ use crate::{
DatabaseLockPoisonError, GameHandleCreationError, LoadOrderError, LoadOrderStateError,
LoadPluginsError, SortPluginsError,
},
escape_ascii,
logging::{self, format_details, is_log_enabled},
metadata::{
Filename,
@@ -155,9 +156,9 @@ impl Game {
/// can be used to provide the local path instead.
pub fn new(game_type: GameType, game_path: &Path) -> Result<Self, GameHandleCreationError> {
logging::info!(
"Attempting to create a game handle for game type \"{}\" with game path {:?}",
"Attempting to create a game handle for game type \"{}\" with game path \"{}\"",
game_type,
game_path
escape_ascii(game_path)
);
let resolved_game_path = resolve_path(game_path);
@@ -197,10 +198,10 @@ impl Game {
game_local_path: &Path,
) -> Result<Self, GameHandleCreationError> {
logging::info!(
"Attempting to create a game handle for game type \"{}\" with game path {:?} and game local path {:?}",
"Attempting to create a game handle for game type \"{}\" with game path \"{}\" and game local path \"{}\"",
game_type,
game_path,
game_local_path
escape_ascii(game_path),
escape_ascii(game_local_path)
);
let resolved_game_path = resolve_path(game_path);
@@ -671,7 +672,7 @@ fn try_load_plugin(
Err(e) => {
logging::error!(
"Caught error while trying to load \"{}\": {}",
plugin_path.display(),
escape_ascii(plugin_path),
format_details(&e)
);
None
@@ -685,8 +686,8 @@ fn resolve_plugin_path(game_type: GameType, data_path: &Path, plugin_path: &Path
if game_type != GameType::OpenMW && !plugin_path.exists() {
if let Some(filename) = plugin_path.file_name() {
logging::debug!(
"Could not find plugin at {}, adding {} file extension",
plugin_path.display(),
"Could not find plugin at \"{}\", adding {} file extension",
escape_ascii(&plugin_path),
GHOST_FILE_EXTENSION
);
let mut filename = filename.to_os_string();
+7 -7
View File
@@ -5,7 +5,7 @@ use std::{
use saphyr::{LoadableYamlNode, MarkedYaml, YamlData};
use crate::logging;
use crate::{escape_ascii, logging};
use super::{
error::{
@@ -37,7 +37,7 @@ impl MetadataDocument {
));
}
logging::trace!("Loading file: {:?}", file_path);
logging::trace!("Loading file at \"{}\"", escape_ascii(file_path));
let content = std::fs::read_to_string(file_path)
.map_err(|e| LoadMetadataError::from_io_error(file_path.into(), e))?;
@@ -46,8 +46,8 @@ impl MetadataDocument {
.map_err(|e| LoadMetadataError::new(file_path.into(), e))?;
logging::trace!(
"Successfully loaded metadata from file at \"{:?}\".",
file_path
"Successfully loaded metadata from file at \"{}\".",
escape_ascii(file_path)
);
Ok(())
@@ -84,8 +84,8 @@ impl MetadataDocument {
.map_err(|e| LoadMetadataError::new(masterlist_path.into(), e))?;
logging::trace!(
"Successfully loaded metadata from file at \"{:?}\".",
masterlist_path
"Successfully loaded metadata from file at \"{}\".",
escape_ascii(masterlist_path)
);
Ok(())
@@ -198,7 +198,7 @@ impl MetadataDocument {
}
pub fn save(&self, file_path: &Path) -> Result<(), WriteMetadataError> {
logging::trace!("Saving metadata list to: {}", file_path.display());
logging::trace!("Saving metadata list to: \"{}\"", escape_ascii(file_path));
let mut emitter = YamlEmitter::new();
+3 -3
View File
@@ -15,7 +15,7 @@ use fancy_regex::{Error as RegexImplError, Regex};
use crate::{
GameType,
archive::{assets_in_archives, do_assets_overlap, find_associated_archives},
case_insensitive_regex,
case_insensitive_regex, escape_ascii,
game::GameCache,
logging,
metadata::plugin_metadata::trim_dot_ghost,
@@ -289,7 +289,7 @@ pub(crate) fn validate_plugin_path_and_header(
} else if !has_plugin_file_extension(game_type, plugin_path) {
logging::debug!(
"The file \"{}\" is not a valid plugin",
plugin_path.display()
escape_ascii(plugin_path)
);
Err(PluginValidationError::invalid(
plugin_path.into(),
@@ -301,7 +301,7 @@ pub(crate) fn validate_plugin_path_and_header(
} else {
logging::debug!(
"The file \"{}\" is not a valid plugin",
plugin_path.display()
escape_ascii(plugin_path)
);
Err(PluginValidationError::new(
plugin_path.into(),