@@ -5,21 +5,14 @@ use std::{
55
66use bstr:: { BStr , BString , ByteSlice } ;
77
8+ use gix_error:: { message, ErrorExt } ;
9+
810use crate :: Stack ;
911
1012///
1113pub 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+ . map_err ( |_| message ( "Could not convert to UTF8 or from UTF8 due to ill-formed input" ) . raise ( ) )
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