diff --git a/Cargo.lock b/Cargo.lock index 9f0e4eb745..de308bb386 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1827,13 +1827,13 @@ dependencies = [ "bstr", "crossbeam-channel", "fastrand", + "gix-error", "gix-features", "gix-path", "gix-utils", "is_ci", "serde", "tempfile", - "thiserror 2.0.18", ] [[package]] diff --git a/gix-fs/Cargo.toml b/gix-fs/Cargo.toml index 5b9de9c7ba..75492b0894 100644 --- a/gix-fs/Cargo.toml +++ b/gix-fs/Cargo.toml @@ -23,7 +23,7 @@ bstr = "1.12.0" gix-path = { version = "^0.11.2", path = "../gix-path" } gix-features = { version = "^0.46.2", path = "../gix-features", features = ["fs-read-dir"] } gix-utils = { version = "^0.3.1", path = "../gix-utils" } -thiserror = "2.0.18" +gix-error = { version = "0.1.0", path = "../gix-error" } serde = { version = "1.0.114", optional = true, default-features = false, features = ["std", "derive"] } # For `Capabilities` to assure parallel operation works. diff --git a/gix-fs/src/stack.rs b/gix-fs/src/stack.rs index 11aebe3f83..83e3b3a33a 100644 --- a/gix-fs/src/stack.rs +++ b/gix-fs/src/stack.rs @@ -5,21 +5,14 @@ use std::{ use bstr::{BStr, BString, ByteSlice}; +use gix_error::{message, ErrorExt, ResultExt}; + use crate::Stack; /// pub mod to_normal_path_components { - use std::path::PathBuf; - /// The error used in [`ToNormalPathComponents::to_normal_path_components()`](super::ToNormalPathComponents::to_normal_path_components()). - #[derive(Debug, thiserror::Error)] - #[allow(missing_docs)] - pub enum Error { - #[error("Input path \"{path}\" contains relative or absolute components", path = .0.display())] - NotANormalComponent(PathBuf), - #[error("Could not convert to UTF8 or from UTF8 due to ill-formed input")] - IllegalUtf8, - } + pub type Error = gix_error::Exn; } /// Obtain an iterator over `OsStr`-components which are normal, none-relative and not absolute. @@ -46,9 +39,11 @@ fn component_to_os_str<'a>( ) -> Result<&'a OsStr, to_normal_path_components::Error> { match component { Component::Normal(os_str) => Ok(os_str), - _ => Err(to_normal_path_components::Error::NotANormalComponent( - path_with_component.to_owned(), - )), + _ => Err(message!( + "Input path \"{}\" contains relative or absolute components", + path_with_component.display() + ) + .raise()), } } @@ -81,7 +76,7 @@ fn bytes_component_to_os_str<'a>( return None; } let component = match gix_path::try_from_byte_slice(component.as_bstr()) - .map_err(|_| to_normal_path_components::Error::IllegalUtf8) + .or_raise(|| message("Could not convert to UTF8 or from UTF8 due to ill-formed input")) { Ok(c) => c, Err(err) => return Some(Err(err)), @@ -178,7 +173,7 @@ impl Stack { break; } } - Err(err) => return Err(std::io::Error::other(format!("{err}"))), + Err(err) => return Err(std::io::Error::other(err.to_string())), } } @@ -197,7 +192,7 @@ impl Stack { } while let Some(comp) = components.next() { - let comp = comp.map_err(std::io::Error::other)?; + let comp = comp.map_err(|e| std::io::Error::other(e.into_error()))?; let is_last_component = components.peek().is_none(); self.current_is_directory = !is_last_component; self.current.push(comp);