refactor: Capitalize error messages

This commit is contained in:
Lucas Schwiderski 2023-03-08 20:34:45 +01:00
parent 658d996315
commit a8db19cf9f
Signed by: lucas
GPG key ID: AA12679AAA6DF4D8
18 changed files with 125 additions and 125 deletions

View file

@ -23,10 +23,10 @@ use super::read_sjson_file;
pub(crate) async fn import_mod(state: ActionState, info: FileInfo) -> Result<ModInfo> {
let data = fs::read(&info.path)
.await
.wrap_err_with(|| format!("failed to read file {}", info.path.display()))?;
.wrap_err_with(|| format!("Failed to read file {}", info.path.display()))?;
let data = Cursor::new(data);
let mut archive = ZipArchive::new(data).wrap_err("failed to open ZIP archive")?;
let mut archive = ZipArchive::new(data).wrap_err("Failed to open ZIP archive")?;
if tracing::enabled!(tracing::Level::DEBUG) {
let names = archive.file_names().fold(String::new(), |mut s, name| {
@ -38,7 +38,7 @@ pub(crate) async fn import_mod(state: ActionState, info: FileInfo) -> Result<Mod
}
let dir_name = {
let f = archive.by_index(0).wrap_err("archive is empty")?;
let f = archive.by_index(0).wrap_err("Archive is empty")?;
if !f.is_dir() {
let err = eyre::eyre!("archive does not have a top-level directory");
@ -62,15 +62,15 @@ pub(crate) async fn import_mod(state: ActionState, info: FileInfo) -> Result<Mod
let mut f = archive
.by_name(name)
.wrap_err("failed to read mod config from archive")?;
.wrap_err("Failed to read mod config from archive")?;
let mut buf = Vec::with_capacity(f.size() as usize);
f.read_to_end(&mut buf)
.wrap_err("failed to read mod config from archive")?;
.wrap_err("Failed to read mod config from archive")?;
let data = String::from_utf8(buf).wrap_err("mod config is not valid UTF-8")?;
let data = String::from_utf8(buf).wrap_err("Mod config is not valid UTF-8")?;
serde_sjson::from_str(&data).wrap_err("failed to deserialize mod config")?
serde_sjson::from_str(&data).wrap_err("Failed to deserialize mod config")?
};
tracing::debug!(?mod_cfg);
@ -83,14 +83,14 @@ pub(crate) async fn import_mod(state: ActionState, info: FileInfo) -> Result<Mod
let mut f = archive
.by_name(name)
.wrap_err("failed to read file index from archive")?;
.wrap_err("Failed to read file index from archive")?;
let mut buf = Vec::with_capacity(f.size() as usize);
f.read_to_end(&mut buf)
.wrap_err("failed to read file index from archive")?;
.wrap_err("Failed to read file index from archive")?;
let data = String::from_utf8(buf).wrap_err("file index is not valid UTF-8")?;
let data = String::from_utf8(buf).wrap_err("File index is not valid UTF-8")?;
serde_sjson::from_str(&data).wrap_err("failed to deserialize file index")?
serde_sjson::from_str(&data).wrap_err("Failed to deserialize file index")?
};
tracing::trace!(?files);
@ -100,12 +100,12 @@ pub(crate) async fn import_mod(state: ActionState, info: FileInfo) -> Result<Mod
tracing::trace!("Creating mods directory {}", mod_dir.display());
fs::create_dir_all(Arc::as_ref(&mod_dir))
.await
.wrap_err_with(|| format!("failed to create data directory {}", mod_dir.display()))?;
.wrap_err_with(|| format!("Failed to create data directory {}", mod_dir.display()))?;
tracing::trace!("Extracting mod archive to {}", mod_dir.display());
archive
.extract(Arc::as_ref(&mod_dir))
.wrap_err_with(|| format!("failed to extract archive to {}", mod_dir.display()))?;
.wrap_err_with(|| format!("Failed to extract archive to {}", mod_dir.display()))?;
let packages = files
.into_iter()
@ -121,7 +121,7 @@ pub(crate) async fn delete_mod(state: ActionState, info: &ModInfo) -> Result<()>
let mod_dir = state.mod_dir.join(&info.id);
fs::remove_dir_all(&mod_dir)
.await
.wrap_err_with(|| format!("failed to remove directory {}", mod_dir.display()))?;
.wrap_err_with(|| format!("Failed to remove directory {}", mod_dir.display()))?;
Ok(())
}
@ -133,7 +133,7 @@ pub(crate) async fn save_settings(state: ActionState) -> Result<()> {
tracing::info!("Saving settings to '{}'", state.config_path.display());
tracing::debug!(?cfg);
let data = serde_sjson::to_string(&cfg).wrap_err("failed to serialize config")?;
let data = serde_sjson::to_string(&cfg).wrap_err("Failed to serialize config")?;
fs::write(state.config_path.as_ref(), &data)
.await
@ -155,11 +155,11 @@ async fn read_mod_dir_entry(res: Result<DirEntry>) -> Result<ModInfo> {
let cfg: ModConfig = read_sjson_file(&config_path)
.await
.wrap_err_with(|| format!("failed to read mod config '{}'", config_path.display()))?;
.wrap_err_with(|| format!("Failed to read mod config '{}'", config_path.display()))?;
let files: HashMap<String, Vec<String>> = read_sjson_file(&index_path)
.await
.wrap_err_with(|| format!("failed to read file index '{}'", index_path.display()))?;
.wrap_err_with(|| format!("Failed to read file index '{}'", index_path.display()))?;
let packages = files
.into_iter()
@ -186,12 +186,12 @@ where
}
Err(err) => {
return Err(err)
.wrap_err_with(|| format!("failed to open directory '{}'", mod_dir.display()));
.wrap_err_with(|| format!("Failed to open directory '{}'", mod_dir.display()));
}
};
let stream = ReadDirStream::new(read_dir)
.map(|res| res.wrap_err("failed to read dir entry"))
.map(|res| res.wrap_err("Failed to read dir entry"))
.then(read_mod_dir_entry);
tokio::pin!(stream);

View file

@ -74,7 +74,7 @@ where
);
fs::copy(path, &backup_path).await.wrap_err_with(|| {
format!(
"failed to back up {} '{}' to '{}'",
"Failed to back up {} '{}' to '{}'",
file_name,
path.display(),
backup_path.display()
@ -83,13 +83,13 @@ where
tracing::debug!("Reading {} from original '{}'", file_name, path.display());
fs::read(path).await.wrap_err_with(|| {
format!("failed to read {} file: {}", file_name, path.display())
format!("Failed to read {} file: {}", file_name, path.display())
})?
}
Err(err) => {
return Err(err).wrap_err_with(|| {
format!(
"failed to read {} from backup '{}'",
"Failed to read {} from backup '{}'",
file_name,
backup_path.display()
)
@ -105,12 +105,12 @@ async fn patch_game_settings(state: Arc<ActionState>) -> Result<()> {
let settings = read_file_with_backup(&settings_path)
.await
.wrap_err("failed to read settings.ini")?;
let settings = String::from_utf8(settings).wrap_err("settings.ini is not valid UTF-8")?;
.wrap_err("Failed to read settings.ini")?;
let settings = String::from_utf8(settings).wrap_err("Settings.ini is not valid UTF-8")?;
let mut f = fs::File::create(&settings_path)
.await
.wrap_err_with(|| format!("failed to open {}", settings_path.display()))?;
.wrap_err_with(|| format!("Failed to open {}", settings_path.display()))?;
let Some(i) = settings.find("boot_script =") else {
eyre::bail!("couldn't find 'boot_script' field");
@ -138,7 +138,7 @@ fn make_package(info: &PackageInfo) -> Result<Package> {
.next()
.ok_or_else(|| eyre::eyre!("missing file extension"))
.and_then(BundleFileType::from_str)
.wrap_err("invalid file name in package info")?;
.wrap_err("Invalid file name in package info")?;
let name: String = it.collect();
pkg.add_file(file_type, name);
}
@ -216,9 +216,9 @@ async fn build_bundles(state: Arc<ActionState>) -> Result<Vec<Bundle>> {
let _enter = span.enter();
let lua = build_mod_data_lua(state.clone());
let lua = CString::new(lua).wrap_err("failed to build CString from mod data Lua string")?;
let lua = CString::new(lua).wrap_err("Failed to build CString from mod data Lua string")?;
let file =
lua::compile(MOD_DATA_SCRIPT, &lua).wrap_err("failed to compile mod data Lua file")?;
lua::compile(MOD_DATA_SCRIPT, &lua).wrap_err("Failed to compile mod data Lua file")?;
mod_bundle.add_file(file);
}
@ -232,11 +232,11 @@ async fn build_bundles(state: Arc<ActionState>) -> Result<Vec<Bundle>> {
let span = tracing::trace_span!("building package", name = pkg_info.name);
let _enter = span.enter();
let pkg = make_package(pkg_info).wrap_err("failed to make package")?;
let pkg = make_package(pkg_info).wrap_err("Failed to make package")?;
let mut variant = BundleFileVariant::new();
let bin = pkg
.to_binary()
.wrap_err("failed to serialize package to binary")?;
.wrap_err("Failed to serialize package to binary")?;
variant.set_data(bin);
let mut file = BundleFile::new(pkg_info.name.clone(), BundleFileType::Package);
file.add_variant(variant);
@ -260,11 +260,11 @@ async fn build_bundles(state: Arc<ActionState>) -> Result<Vec<Bundle>> {
let task = async move {
let bundle = {
let bin = fs::read(&src).await.wrap_err_with(|| {
format!("failed to read bundle file '{}'", src.display())
format!("Failed to read bundle file '{}'", src.display())
})?;
let name = Bundle::get_name_from_path(&ctx, &src);
Bundle::from_binary(&ctx, name, bin)
.wrap_err_with(|| format!("failed to parse bundle '{}'", src.display()))?
.wrap_err_with(|| format!("Failed to parse bundle '{}'", src.display()))?
};
tracing::debug!(
@ -283,7 +283,7 @@ async fn build_bundles(state: Arc<ActionState>) -> Result<Vec<Bundle>> {
let _ = fs::remove_file(&dest).await;
fs::copy(&src, &dest).await.wrap_err_with(|| {
format!(
"failed to copy bundle {pkg_name} for mod {mod_name}. src: {}, dest: {}",
"Failed to copy bundle {pkg_name} for mod {mod_name}. Src: {}, dest: {}",
src.display(),
dest.display()
)
@ -311,7 +311,7 @@ async fn build_bundles(state: Arc<ActionState>) -> Result<Vec<Bundle>> {
tracing::trace!("Writing mod bundle to '{}'", path.display());
fs::write(&path, mod_bundle.to_binary()?)
.await
.wrap_err_with(|| format!("failed to write bundle to '{}'", path.display()))?;
.wrap_err_with(|| format!("Failed to write bundle to '{}'", path.display()))?;
}
bundles.push(mod_bundle);
@ -329,14 +329,14 @@ async fn patch_boot_bundle(state: Arc<ActionState>) -> Result<Vec<Bundle>> {
let mut boot_bundle = async {
let bin = read_file_with_backup(&bundle_path)
.await
.wrap_err("failed to read boot bundle")?;
.wrap_err("Failed to read boot bundle")?;
Bundle::from_binary(&state.ctx, BOOT_BUNDLE_NAME.to_string(), bin)
.wrap_err("failed to parse boot bundle")
.wrap_err("Failed to parse boot bundle")
}
.instrument(tracing::trace_span!("read boot bundle"))
.await
.wrap_err_with(|| format!("failed to read bundle '{}'", BOOT_BUNDLE_NAME))?;
.wrap_err_with(|| format!("Failed to read bundle '{}'", BOOT_BUNDLE_NAME))?;
{
tracing::trace!("Adding mod package file to boot bundle");
@ -386,11 +386,11 @@ async fn patch_boot_bundle(state: Arc<ActionState>) -> Result<Vec<Bundle>> {
{
let bin = fs::read(&src)
.await
.wrap_err_with(|| format!("failed to read bundle file '{}'", src.display()))?;
.wrap_err_with(|| format!("Failed to read bundle file '{}'", src.display()))?;
let name = Bundle::get_name_from_path(&state.ctx, &src);
let dml_bundle = Bundle::from_binary(&state.ctx, name, bin)
.wrap_err_with(|| format!("failed to parse bundle '{}'", src.display()))?;
.wrap_err_with(|| format!("Failed to parse bundle '{}'", src.display()))?;
bundles.push(dml_bundle);
};
@ -416,14 +416,14 @@ async fn patch_boot_bundle(state: Arc<ActionState>) -> Result<Vec<Bundle>> {
let _ = fs::remove_file(&dest).await;
fs::copy(&src, &dest).await.wrap_err_with(|| {
format!(
"failed to copy bundle {pkg_name} for mod {mod_name}. src: {}, dest: {}",
"Failed to copy bundle {pkg_name} for mod {mod_name}. Src: {}, dest: {}",
src.display(),
dest.display()
)
})?;
}
let pkg = make_package(pkg_info).wrap_err("failed to create package file for dml")?;
let pkg = make_package(pkg_info).wrap_err("Failed to create package file for dml")?;
variant.set_data(pkg.to_binary()?);
let mut f = BundleFile::new(DML_BUNDLE_NAME.to_string(), BundleFileType::Package);
@ -437,9 +437,9 @@ async fn patch_boot_bundle(state: Arc<ActionState>) -> Result<Vec<Bundle>> {
let _enter = span.enter();
let lua = include_str!("../../assets/mod_main.lua");
let lua = CString::new(lua).wrap_err("failed to build CString from mod main Lua string")?;
let lua = CString::new(lua).wrap_err("Failed to build CString from mod main Lua string")?;
let file =
lua::compile(MOD_BOOT_SCRIPT, &lua).wrap_err("failed to compile mod main Lua file")?;
lua::compile(MOD_BOOT_SCRIPT, &lua).wrap_err("Failed to compile mod main Lua file")?;
boot_bundle.add_file(file);
}
@ -447,10 +447,10 @@ async fn patch_boot_bundle(state: Arc<ActionState>) -> Result<Vec<Bundle>> {
async {
let bin = boot_bundle
.to_binary()
.wrap_err("failed to serialize boot bundle")?;
.wrap_err("Failed to serialize boot bundle")?;
fs::write(&bundle_path, bin)
.await
.wrap_err_with(|| format!("failed to write main bundle: {}", bundle_path.display()))
.wrap_err_with(|| format!("Failed to write main bundle: {}", bundle_path.display()))
}
.instrument(tracing::trace_span!("write boot bundle"))
.await?;
@ -471,9 +471,9 @@ where
let mut db = {
let bin = read_file_with_backup(&database_path)
.await
.wrap_err("failed to read bundle database")?;
.wrap_err("Failed to read bundle database")?;
let mut r = Cursor::new(bin);
let db = BundleDatabase::from_binary(&mut r).wrap_err("failed to parse bundle database")?;
let db = BundleDatabase::from_binary(&mut r).wrap_err("Failed to parse bundle database")?;
tracing::trace!("Finished parsing bundle database");
db
};
@ -486,7 +486,7 @@ where
{
let bin = db
.to_binary()
.wrap_err("failed to serialize bundle database")?;
.wrap_err("Failed to serialize bundle database")?;
fs::write(&database_path, bin).await.wrap_err_with(|| {
format!(
"failed to write bundle database to '{}'",
@ -512,11 +512,11 @@ where
.collect(),
};
let path = state.game_dir.join(DEPLOYMENT_DATA_PATH);
let data = serde_sjson::to_string(&info).wrap_err("failed to serizalie deployment data")?;
let data = serde_sjson::to_string(&info).wrap_err("Failed to serizalie deployment data")?;
fs::write(&path, &data)
.await
.wrap_err_with(|| format!("failed to write deployment data to '{}'", path.display()))?;
.wrap_err_with(|| format!("Failed to write deployment data to '{}'", path.display()))?;
Ok(())
}
@ -552,15 +552,15 @@ pub(crate) async fn deploy_mods(state: ActionState) -> Result<()> {
if let Some(err) = err.downcast_ref::<std::io::Error>() && err.kind() == ErrorKind::NotFound {
Ok(None)
} else {
Err(err).wrap_err("failed to read deployment data")
Err(err).wrap_err("Failed to read deployment data")
}
}
}
}
)
.wrap_err("failed to gather deployment information")?;
.wrap_err("Failed to gather deployment information")?;
let game_info = game_info.wrap_err("failed to collect Steam info")?;
let game_info = game_info.wrap_err("Failed to collect Steam info")?;
tracing::debug!(?game_info, ?deployment_info);
@ -581,12 +581,12 @@ pub(crate) async fn deploy_mods(state: ActionState) -> Result<()> {
tracing::info!("Build mod bundles");
let mut bundles = build_bundles(state.clone())
.await
.wrap_err("failed to build mod bundles")?;
.wrap_err("Failed to build mod bundles")?;
tracing::info!("Patch boot bundle");
let mut more_bundles = patch_boot_bundle(state.clone())
.await
.wrap_err("failed to patch boot bundle")?;
.wrap_err("Failed to patch boot bundle")?;
bundles.append(&mut more_bundles);
if let Some(info) = &deployment_info {
@ -609,7 +609,7 @@ pub(crate) async fn deploy_mods(state: ActionState) -> Result<()> {
tracing::debug!("Removing unused bundle '{}'", file_name);
if let Err(err) = fs::remove_file(&path).await.wrap_err_with(|| {
format!("failed to remove unused bundle '{}'", path.display())
format!("Failed to remove unused bundle '{}'", path.display())
}) {
tracing::error!("{:?}", err);
}
@ -626,17 +626,17 @@ pub(crate) async fn deploy_mods(state: ActionState) -> Result<()> {
tracing::info!("Patch game settings");
patch_game_settings(state.clone())
.await
.wrap_err("failed to patch game settings")?;
.wrap_err("Failed to patch game settings")?;
tracing::info!("Patching bundle database");
patch_bundle_database(state.clone(), &bundles)
.await
.wrap_err("failed to patch bundle database")?;
.wrap_err("Failed to patch bundle database")?;
tracing::info!("Writing deployment data");
write_deployment_data(state.clone(), &bundles)
.await
.wrap_err("failed to write deployment data")?;
.wrap_err("Failed to write deployment data")?;
tracing::info!("Finished deploying mods");
Ok(())
@ -662,14 +662,14 @@ pub(crate) async fn reset_mod_deployment(state: ActionState) -> Result<()> {
}
Err(err) => {
return Err(err).wrap_err_with(|| {
format!("failed to read deployment info at '{}'", path.display())
format!("Failed to read deployment info at '{}'", path.display())
});
}
};
let data = String::from_utf8(data).wrap_err("invalid UTF8 in deployment data")?;
let data = String::from_utf8(data).wrap_err("Invalid UTF8 in deployment data")?;
serde_sjson::from_str(&data).wrap_err("invalid SJSON in deployment data")?
serde_sjson::from_str(&data).wrap_err("Invalid SJSON in deployment data")?
};
for name in info.bundles {
@ -697,7 +697,7 @@ pub(crate) async fn reset_mod_deployment(state: ActionState) -> Result<()> {
fs::copy(&backup, &path)
.await
.wrap_err_with(|| format!("failed to copy from '{}'", backup.display()))?;
.wrap_err_with(|| format!("Failed to copy from '{}'", backup.display()))?;
tracing::debug!("Deleting backup: {}", backup.display());
@ -705,7 +705,7 @@ pub(crate) async fn reset_mod_deployment(state: ActionState) -> Result<()> {
Ok(_) => Ok(()),
Err(err) if err.kind() == ErrorKind::NotFound => Ok(()),
Err(err) => {
Err(err).wrap_err_with(|| format!("failed to remove '{}'", backup.display()))
Err(err).wrap_err_with(|| format!("Failed to remove '{}'", backup.display()))
}
}
}

View file

@ -17,7 +17,7 @@ where
let path = path.as_ref();
let buf = fs::read(path)
.await
.wrap_err_with(|| format!("failed to read file '{}'", path.display()))?;
let data = String::from_utf8(buf).wrap_err("invalid UTF8")?;
serde_sjson::from_str(&data).wrap_err("failed to deserialize SJSON")
.wrap_err_with(|| format!("Failed to read file '{}'", path.display()))?;
let data = String::from_utf8(buf).wrap_err("Invalid UTF8")?;
serde_sjson::from_str(&data).wrap_err("Failed to deserialize SJSON")
}

View file

@ -34,7 +34,7 @@ async fn handle_action(
let event_sink = event_sink.clone();
match action {
AsyncAction::DeployMods(state) => tokio::spawn(async move {
if let Err(err) = deploy_mods(state).await.wrap_err("failed to deploy mods") {
if let Err(err) = deploy_mods(state).await.wrap_err("Failed to deploy mods") {
tracing::error!("{:?}", err);
send_error(event_sink.clone(), err).await;
}
@ -48,7 +48,7 @@ async fn handle_action(
AsyncAction::AddMod(state, info) => tokio::spawn(async move {
match import_mod(state, info)
.await
.wrap_err("failed to import mod")
.wrap_err("Failed to import mod")
{
Ok(mod_info) => {
event_sink
@ -71,7 +71,7 @@ async fn handle_action(
let mod_dir = state.mod_dir.join(&info.id);
if let Err(err) = delete_mod(state, &info)
.await
.wrap_err("failed to delete mod files")
.wrap_err("Failed to delete mod files")
.with_suggestion(|| {
format!("Clean the folder '{}' manually", mod_dir.display())
})
@ -93,7 +93,7 @@ async fn handle_action(
AsyncAction::ResetDeployment(state) => tokio::spawn(async move {
if let Err(err) = reset_mod_deployment(state)
.await
.wrap_err("failed to reset mod deployment")
.wrap_err("Failed to reset mod deployment")
{
tracing::error!("{:?}", err);
send_error(event_sink.clone(), err).await;
@ -108,7 +108,7 @@ async fn handle_action(
AsyncAction::SaveSettings(state) => tokio::spawn(async move {
if let Err(err) = save_settings(state)
.await
.wrap_err("failed to save settings")
.wrap_err("Failed to save settings")
{
tracing::error!("{:?}", err);
send_error(event_sink.clone(), err).await;

View file

@ -58,7 +58,7 @@ fn main() -> Result<()> {
}
let config = util::config::read_config(&default_config_path, &matches)
.wrap_err("failed to read config file")?;
.wrap_err("Failed to read config file")?;
let game_info = dtmt_shared::collect_game_info()?;
@ -71,7 +71,7 @@ fn main() -> Result<()> {
config.data_dir.unwrap_or_default(),
);
state.mods = load_mods(state.get_mod_dir(), config.mod_order.iter())
.wrap_err("failed to load mods")?;
.wrap_err("Failed to load mods")?;
state
};

View file

@ -113,10 +113,10 @@ where
match fs::read(path) {
Ok(data) => {
let data = String::from_utf8(data).wrap_err_with(|| {
format!("config file {} contains invalid UTF-8", path.display())
format!("Config file '{}' contains invalid UTF-8", path.display())
})?;
let mut cfg: Config = serde_sjson::from_str(&data)
.wrap_err_with(|| format!("invalid config file {}", path.display()))?;
.wrap_err_with(|| format!("Invalid config file {}", path.display()))?;
cfg.path = path.clone();
Ok(cfg)
@ -124,7 +124,7 @@ where
Err(err) if err.kind() == ErrorKind::NotFound => {
if matches.value_source("config") != Some(ValueSource::DefaultValue) {
return Err(err)
.wrap_err_with(|| format!("failed to read config file {}", path.display()))?;
.wrap_err_with(|| format!("Failed to read config file {}", path.display()))?;
}
{
@ -132,7 +132,7 @@ where
.parent()
.expect("a file path always has a parent directory");
fs::create_dir_all(parent).wrap_err_with(|| {
format!("failed to create directories {}", parent.display())
format!("Failed to create directories {}", parent.display())
})?;
}
@ -145,7 +145,7 @@ where
{
let data = serde_sjson::to_string(&config)
.wrap_err("failed to serialize default config value")?;
.wrap_err("Failed to serialize default config value")?;
fs::write(&config.path, data).wrap_err_with(|| {
format!(
"failed to write default config to {}",
@ -157,7 +157,7 @@ where
Ok(config)
}
Err(err) => {
Err(err).wrap_err_with(|| format!("failed to read config file {}", path.display()))
Err(err).wrap_err_with(|| format!("Failed to read config file {}", path.display()))
}
}
}

View file

@ -66,7 +66,7 @@ async fn find_project_config(dir: Option<PathBuf>) -> Result<ModConfig> {
let (path, mut file) = if let Some(path) = dir {
let file = File::open(&path.join(PROJECT_CONFIG_NAME))
.await
.wrap_err_with(|| format!("failed to open file: {}", path.display()))
.wrap_err_with(|| format!("Failed to open file: {}", path.display()))
.with_suggestion(|| {
format!(
"Make sure the file at '{}' exists and is readable",
@ -90,7 +90,7 @@ async fn find_project_config(dir: Option<PathBuf>) -> Result<ModConfig> {
}
Err(err) => {
let err = Report::new(err)
.wrap_err(format!("failed to open file: {}", path.display()));
.wrap_err(format!("Failed to open file: {}", path.display()));
return Err(err);
}
}
@ -100,10 +100,10 @@ async fn find_project_config(dir: Option<PathBuf>) -> Result<ModConfig> {
let mut buf = String::new();
file.read_to_string(&mut buf)
.await
.wrap_err("invalid UTF-8")?;
.wrap_err("Invalid UTF-8")?;
let mut cfg: ModConfig =
serde_sjson::from_str(&buf).wrap_err("failed to deserialize mod config")?;
serde_sjson::from_str(&buf).wrap_err("Failed to deserialize mod config")?;
cfg.dir = path;
Ok(cfg)
}
@ -175,18 +175,18 @@ where
path.set_extension("package");
let sjson = fs::read_to_string(&path)
.await
.wrap_err_with(|| format!("failed to read file {}", path.display()))?;
.wrap_err_with(|| format!("Failed to read file {}", path.display()))?;
let pkg_name = package.to_slash_lossy().to_string();
let pkg = Package::from_sjson(sjson, pkg_name.clone(), root)
.await
.wrap_err_with(|| format!("invalid package file {}", &pkg_name))?;
.wrap_err_with(|| format!("Invalid package file {}", &pkg_name))?;
compile_package_files(&pkg, root)
.await
.wrap_err("failed to compile package")
.wrap_err("Failed to compile package")
.and_then(|files| compile_bundle(pkg_name, files))
.wrap_err("failed to build bundle")
.wrap_err("Failed to build bundle")
}
fn normalize_file_path<P: AsRef<Path>>(path: P) -> Result<PathBuf> {
@ -211,7 +211,7 @@ pub(crate) async fn read_project_config(dir: Option<PathBuf>) -> Result<ModConfi
let mut cfg = find_project_config(dir).await?;
cfg.resources.init = normalize_file_path(cfg.resources.init)
.wrap_err("invalid config field 'resources.init'")
.wrap_err("Invalid config field 'resources.init'")
.with_suggestion(|| {
"Specify a file path relative to and child path of the \
directory where 'dtmt.cfg' is."
@ -225,7 +225,7 @@ pub(crate) async fn read_project_config(dir: Option<PathBuf>) -> Result<ModConfi
if let Some(path) = cfg.resources.data {
let path = normalize_file_path(path)
.wrap_err("invalid config field 'resources.data'")
.wrap_err("Invalid config field 'resources.data'")
.with_suggestion(|| {
"Specify a file path relative to and child path of the \
directory where 'dtmt.cfg' is."
@ -241,7 +241,7 @@ pub(crate) async fn read_project_config(dir: Option<PathBuf>) -> Result<ModConfi
if let Some(path) = cfg.resources.localization {
let path = normalize_file_path(path)
.wrap_err("invalid config field 'resources.localization'")
.wrap_err("Invalid config field 'resources.localization'")
.with_suggestion(|| {
"Specify a file path relative to and child path of the \
directory where 'dtmt.cfg' is."
@ -281,7 +281,7 @@ pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()>
fs::create_dir_all(out_path)
.await
.wrap_err_with(|| format!("failed to create output directory '{}'", out_path.display()))?;
.wrap_err_with(|| format!("Failed to create output directory '{}'", out_path.display()))?;
let file_map = Arc::new(Mutex::new(FileIndexMap::new()));
@ -335,7 +335,7 @@ pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()>
);
fs::write(&path, &data)
.await
.wrap_err_with(|| format!("failed to write bundle to '{}'", path.display()))?;
.wrap_err_with(|| format!("Failed to write bundle to '{}'", path.display()))?;
if let Some(game_dir) = game_dir.as_ref() {
let path = game_dir.join(&name);
@ -347,7 +347,7 @@ pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()>
);
fs::write(&path, &data)
.await
.wrap_err_with(|| format!("failed to write bundle to '{}'", path.display()))?;
.wrap_err_with(|| format!("Failed to write bundle to '{}'", path.display()))?;
}
Ok(())
@ -355,7 +355,7 @@ pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()>
try_join_all(tasks)
.await
.wrap_err("failed to build mod bundles")?;
.wrap_err("Failed to build mod bundles")?;
{
let file_map = file_map.lock().await;
@ -363,7 +363,7 @@ pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()>
let path = out_path.join("files.sjson");
fs::write(&path, data)
.await
.wrap_err_with(|| format!("failed to write file index to '{}'", path.display()))?;
.wrap_err_with(|| format!("Failed to write file index to '{}'", path.display()))?;
}
tracing::info!("Compiled bundles written to '{}'", out_path.display());

View file

@ -61,7 +61,7 @@ pub(crate) async fn run(ctx: sdk::Context, matches: &ArgMatches) -> Result<()> {
if let Some(name) = matches.get_one::<String>("replace") {
let mut file = File::open(&file_path)
.await
.wrap_err_with(|| format!("failed to open '{}'", file_path.display()))?;
.wrap_err_with(|| format!("Failed to open '{}'", file_path.display()))?;
if let Some(variant) = bundle
.files_mut()
@ -72,7 +72,7 @@ pub(crate) async fn run(ctx: sdk::Context, matches: &ArgMatches) -> Result<()> {
let mut data = Vec::new();
file.read_to_end(&mut data)
.await
.wrap_err("failed to read input file")?;
.wrap_err("Failed to read input file")?;
variant.set_data(data);
} else {
let err = eyre::eyre!("No file '{}' in this bundle.", name)
@ -99,11 +99,11 @@ pub(crate) async fn run(ctx: sdk::Context, matches: &ArgMatches) -> Result<()> {
let out_path = matches.get_one::<PathBuf>("output").unwrap_or(bundle_path);
let data = bundle
.to_binary()
.wrap_err("failed to write changed bundle to output")?;
.wrap_err("Failed to write changed bundle to output")?;
fs::write(out_path, &data)
.await
.wrap_err("failed to write data to output file")?;
.wrap_err("Failed to write data to output file")?;
Ok(())
} else {

View file

@ -98,7 +98,7 @@ pub(crate) async fn run(ctx: sdk::Context, matches: &ArgMatches) -> Result<()> {
async move {
if let Err(err) = print_bundle_contents(&ctx, &p, fmt)
.await
.wrap_err_with(|| format!("failed to list contents of bundle {}", p.display()))
.wrap_err_with(|| format!("Failed to list contents of bundle {}", p.display()))
{
tracing::error!("{err:?}");
}

View file

@ -122,7 +122,7 @@ pub(crate) async fn run(mut ctx: sdk::Context, matches: &ArgMatches) -> Result<(
.expect("required argument not found");
u64::from_str_radix(s, 16)
.wrap_err("failed to parse argument as hexadecimal string")?
.wrap_err("Failed to parse argument as hexadecimal string")?
};
let groups = sub_matches

View file

@ -86,7 +86,7 @@ pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()>
let root = if let Some(dir) = matches.get_one::<String>("root") {
if dir == "." {
std::env::current_dir()
.wrap_err("the current working dir is invalid")
.wrap_err("The current working dir is invalid")
.with_suggestion(|| "Change to a different directory.")?
} else {
PathBuf::from(dir)
@ -142,13 +142,13 @@ pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()>
.recursive(true)
.create(&dir)
.await
.wrap_err_with(|| format!("failed to create directory {}", dir.display()))?;
.wrap_err_with(|| format!("Failed to create directory {}", dir.display()))?;
tracing::trace!("Writing file {}", path.display());
fs::write(&path, content.as_bytes())
.await
.wrap_err_with(|| format!("failed to write content to path {}", path.display()))
.wrap_err_with(|| format!("Failed to write content to path {}", path.display()))
});
futures::stream::iter(templates)

View file

@ -52,7 +52,7 @@ async fn process_dir_entry(res: Result<DirEntry>) -> Result<(OsString, Vec<u8>)>
let data = fs::read(&path)
.await
.wrap_err_with(|| format!("failed to read '{}'", path.display()))?;
.wrap_err_with(|| format!("Failed to read '{}'", path.display()))?;
Ok((entry.file_name(), data))
}
@ -87,7 +87,7 @@ pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()>
let data = fs::read(&path)
.await
.wrap_err_with(|| format!("failed to read mod config at {}", path.display()))?;
.wrap_err_with(|| format!("Failed to read mod config at {}", path.display()))?;
zip.start_file(name.to_slash_lossy(), Default::default())?;
zip.write_all(&data)?;
@ -101,10 +101,10 @@ pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()>
);
let read_dir = fs::read_dir(&path)
.await
.wrap_err_with(|| format!("failed to read directory '{}'", path.display()))?;
.wrap_err_with(|| format!("Failed to read directory '{}'", path.display()))?;
let stream = ReadDirStream::new(read_dir)
.map(|res| res.wrap_err("failed to read dir entry"))
.map(|res| res.wrap_err("Failed to read dir entry"))
.then(process_dir_entry);
tokio::pin!(stream);
@ -121,7 +121,7 @@ pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()>
fs::write(&dest, data.into_inner())
.await
.wrap_err_with(|| format!("failed to write mod archive to '{}'", dest.display()))
.wrap_err_with(|| format!("Failed to write mod archive to '{}'", dest.display()))
.with_suggestion(|| "Make sure that parent directories exist.".to_string())?;
tracing::info!("Mod archive written to {}", dest.display());

View file

@ -75,7 +75,7 @@ async fn main() -> Result<()> {
tokio::spawn(async move {
let res = File::open(&path)
.await
.wrap_err_with(|| format!("failed to open dictionary file: {}", path.display()));
.wrap_err_with(|| format!("Failed to open dictionary file: {}", path.display()));
let f = match res {
Ok(f) => f,
@ -102,7 +102,7 @@ async fn main() -> Result<()> {
tokio::spawn(async move {
let conf = tokio::task::spawn_blocking(|| {
confy::load::<GlobalConfig>(clap::crate_name!(), None)
.wrap_err("failed to load global configuration")
.wrap_err("Failed to load global configuration")
})
.await;

View file

@ -548,7 +548,7 @@ impl BundleFile {
let _enter = span.enter();
let header = BundleFileVariant::read_header(r)
.wrap_err_with(|| format!("failed to read header {i}"))?;
.wrap_err_with(|| format!("Failed to read header {i}"))?;
// TODO: Figure out how `header.unknown_1` correlates to `properties::DATA`
// if props.contains(Properties::DATA) {
@ -572,18 +572,18 @@ impl BundleFile {
let data = vec![];
let s = r
.read_string_len(header.size)
.wrap_err("failed to read data file name")?;
.wrap_err("Failed to read data file name")?;
(data, Some(s))
} else {
let mut data = vec![0; header.size];
r.read_exact(&mut data)
.wrap_err_with(|| format!("failed to read file {i}"))?;
.wrap_err_with(|| format!("Failed to read file {i}"))?;
let data_file_name = if header.len_data_file_name > 0 {
let s = r
.read_string_len(header.len_data_file_name)
.wrap_err("failed to read data file name")?;
.wrap_err("Failed to read data file name")?;
Some(s)
} else {
None
@ -662,7 +662,7 @@ impl BundleFile {
match file_type {
BundleFileType::Lua => {
let sjson =
CString::new(sjson.as_ref()).wrap_err("failed to build CString from SJSON")?;
CString::new(sjson.as_ref()).wrap_err("Failed to build CString from SJSON")?;
lua::compile(name, sjson)
}
BundleFileType::Unknown(_) => {
@ -784,7 +784,7 @@ impl BundleFile {
}
};
let res = res.wrap_err_with(|| format!("failed to decompile file {name}"));
let res = res.wrap_err_with(|| format!("Failed to decompile file {name}"));
match res {
Ok(files) => files,
Err(err) => {

View file

@ -164,7 +164,7 @@ impl Bundle {
OodleLZ_FuzzSafe::No,
OodleLZ_CheckCRC::No,
)
.wrap_err_with(|| format!("failed to decompress chunk {chunk_index}"))?;
.wrap_err_with(|| format!("Failed to decompress chunk {chunk_index}"))?;
if unpacked_size_tracked < CHUNK_SIZE {
raw_buffer.resize(unpacked_size_tracked, 0);
@ -192,7 +192,7 @@ impl Bundle {
let _enter = span.enter();
let file = BundleFile::from_reader(ctx, &mut r, *props)
.wrap_err_with(|| format!("failed to read file {i}"))?;
.wrap_err_with(|| format!("Failed to read file {i}"))?;
files.push(file);
}

View file

@ -38,7 +38,7 @@ where
lua::lua_setglobal(state, b"code\0".as_ptr() as _);
let name = CString::new(name.as_bytes())
.wrap_err_with(|| format!("cannot convert name into CString: {}", name))?;
.wrap_err_with(|| format!("Cannot convert name into CString: {}", name))?;
lua::lua_pushstring(state, name.as_ptr() as _);
lua::lua_setglobal(state, b"name\0".as_ptr() as _);

View file

@ -148,7 +148,7 @@ impl Package {
None
} else {
let t = BundleFileType::from_str(ty)
.wrap_err("invalid file type in package definition")?;
.wrap_err("Invalid file type in package definition")?;
Some(t)
};
@ -200,7 +200,7 @@ impl Package {
}
}
serde_sjson::to_string(&map).wrap_err("failed to serialize Package to SJSON")
serde_sjson::to_string(&map).wrap_err("Failed to serialize Package to SJSON")
}
#[tracing::instrument("Package::from_binary", skip(binary, ctx), fields(binary_len = binary.as_ref().len()))]

View file

@ -56,7 +56,7 @@ impl TryFrom<&str> for Murmur64 {
fn try_from(value: &str) -> Result<Self, Self::Error> {
u64::from_str_radix(value, 16)
.map(Self)
.wrap_err_with(|| format!("failed to convert value to Murmur64: {value}"))
.wrap_err_with(|| format!("Failed to convert value to Murmur64: {value}"))
}
}
@ -164,7 +164,7 @@ impl TryFrom<&str> for Murmur32 {
fn try_from(value: &str) -> Result<Self, Self::Error> {
u32::from_str_radix(value, 16)
.map(Self)
.wrap_err_with(|| format!("failed to convert value to Murmur32: {value}"))
.wrap_err_with(|| format!("Failed to convert value to Murmur32: {value}"))
}
}