@@ -9,7 +9,7 @@ use std::collections::HashMap;
9
9
use std:: vec;
10
10
11
11
use indextree:: { Arena , Descendants , NodeId } ;
12
- use thiserror :: Error ;
12
+ use snafu :: Snafu ;
13
13
14
14
use crate :: path;
15
15
@@ -113,7 +113,9 @@ impl<T: BlitFile> Tree<T> {
113
113
fn add_child_to_node ( & mut self , node_id : NodeId , parent : & str ) -> Result < ( ) , Error > {
114
114
let node = self . arena . get ( node_id) . unwrap ( ) ;
115
115
let Some ( parent_node) = self . map . get ( parent) else {
116
- return Err ( Error :: MissingParent ( parent. to_owned ( ) ) ) ;
116
+ return Err ( Error :: MissingParent {
117
+ parent : parent. to_owned ( ) ,
118
+ } ) ;
117
119
} ;
118
120
119
121
let others = parent_node
@@ -128,22 +130,17 @@ impl<T: BlitFile> Tree<T> {
128
130
} )
129
131
. collect :: < Vec < _ > > ( ) ;
130
132
if !others. is_empty ( ) {
133
+ let e = Error :: Duplicate {
134
+ node_path : node. get ( ) . path . clone ( ) ,
135
+ node_id : node. get ( ) . id . clone ( ) ,
136
+ other_id : others. first ( ) . unwrap ( ) . id . clone ( ) ,
137
+ } ;
138
+
131
139
// TODO: Reenable
132
- // Err(Error::Duplicate(
133
- // node.get().path(),
134
- // node.get().id(),
135
- // others.first().unwrap().id(),
136
- // ))
140
+ // return Err(e)
137
141
138
142
// Report duplicate and skip for now
139
- eprintln ! (
140
- "error: {}" ,
141
- Error :: Duplicate (
142
- node. get( ) . path. clone( ) ,
143
- node. get( ) . id. clone( ) ,
144
- others. first( ) . unwrap( ) . id. clone( )
145
- )
146
- ) ;
143
+ eprintln ! ( "error: {e}" ) ;
147
144
} else {
148
145
parent_node. append ( node_id, & mut self . arena ) ;
149
146
}
@@ -253,11 +250,15 @@ impl<'a, T: BlitFile> Iterator for TreeIterator<'a, T> {
253
250
}
254
251
}
255
252
256
- #[ derive( Debug , Error ) ]
253
+ #[ derive( Debug , Snafu ) ]
257
254
pub enum Error {
258
- #[ error( "missing parent: {0}" ) ]
259
- MissingParent ( String ) ,
260
-
261
- #[ error( "duplicate entry: {0} {1} attempts to overwrite {2}" ) ]
262
- Duplicate ( String , String , String ) ,
255
+ #[ snafu( display( "missing parent: {parent}" ) ) ]
256
+ MissingParent { parent : String } ,
257
+
258
+ #[ snafu( display( "duplicate entry: {node_path} {node_id} attempts to overwrite {other_id}" ) ) ]
259
+ Duplicate {
260
+ node_path : String ,
261
+ node_id : String ,
262
+ other_id : String ,
263
+ } ,
263
264
}
0 commit comments