Skip to content

Commit 671b892

Browse files
feat!: gix-error instead of thiserror in gix-fs
Replace the thiserror-derived `to_normal_path_components::Error` enum with `gix_error::Exn<gix_error::Message>`. Co-Authored-By: Sebastian Thiel <sebastian.thiel@icloud.com> Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
1 parent 8e47e0f commit 671b892

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gix-fs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ bstr = "1.12.0"
2323
gix-path = { version = "^0.11.1", path = "../gix-path" }
2424
gix-features = { version = "^0.46.1", path = "../gix-features", features = ["fs-read-dir"] }
2525
gix-utils = { version = "^0.3.1", path = "../gix-utils" }
26-
thiserror = "2.0.18"
26+
gix-error = { version = "0.1.0", path = "../gix-error" }
2727
serde = { version = "1.0.114", optional = true, default-features = false, features = ["std", "derive"] }
2828

2929
# For `Capabilities` to assure parallel operation works.

gix-fs/src/stack.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,14 @@ use std::{
55

66
use bstr::{BStr, BString, ByteSlice};
77

8+
use gix_error::{message, ErrorExt, ResultExt};
9+
810
use crate::Stack;
911

1012
///
1113
pub mod to_normal_path_components {
12-
use std::path::PathBuf;
13-
1414
/// The error used in [`ToNormalPathComponents::to_normal_path_components()`](super::ToNormalPathComponents::to_normal_path_components()).
15-
#[derive(Debug, thiserror::Error)]
16-
#[allow(missing_docs)]
17-
pub enum Error {
18-
#[error("Input path \"{path}\" contains relative or absolute components", path = .0.display())]
19-
NotANormalComponent(PathBuf),
20-
#[error("Could not convert to UTF8 or from UTF8 due to ill-formed input")]
21-
IllegalUtf8,
22-
}
15+
pub type Error = gix_error::Exn<gix_error::Message>;
2316
}
2417

2518
/// Obtain an iterator over `OsStr`-components which are normal, none-relative and not absolute.
@@ -46,9 +39,11 @@ fn component_to_os_str<'a>(
4639
) -> Result<&'a OsStr, to_normal_path_components::Error> {
4740
match component {
4841
Component::Normal(os_str) => Ok(os_str),
49-
_ => Err(to_normal_path_components::Error::NotANormalComponent(
50-
path_with_component.to_owned(),
51-
)),
42+
_ => Err(message!(
43+
"Input path \"{}\" contains relative or absolute components",
44+
path_with_component.display()
45+
)
46+
.raise()),
5247
}
5348
}
5449

@@ -81,7 +76,7 @@ fn bytes_component_to_os_str<'a>(
8176
return None;
8277
}
8378
let component = match gix_path::try_from_byte_slice(component.as_bstr())
84-
.map_err(|_| to_normal_path_components::Error::IllegalUtf8)
79+
.or_raise(|| message("Could not convert to UTF8 or from UTF8 due to ill-formed input"))
8580
{
8681
Ok(c) => c,
8782
Err(err) => return Some(Err(err)),
@@ -178,7 +173,7 @@ impl Stack {
178173
break;
179174
}
180175
}
181-
Err(err) => return Err(std::io::Error::other(format!("{err}"))),
176+
Err(err) => return Err(std::io::Error::other(err.to_string())),
182177
}
183178
}
184179

@@ -197,7 +192,7 @@ impl Stack {
197192
}
198193

199194
while let Some(comp) = components.next() {
200-
let comp = comp.map_err(std::io::Error::other)?;
195+
let comp = comp.map_err(|e| std::io::Error::other(e.into_error()))?;
201196
let is_last_component = components.peek().is_none();
202197
self.current_is_directory = !is_last_component;
203198
self.current.push(comp);

0 commit comments

Comments
 (0)