@@ -15,7 +15,7 @@ use string_interner::StringInterner;
1515use string_interner:: backend:: BucketBackend ;
1616use thiserror:: Error ;
1717use uucore:: display:: Quotable ;
18- use uucore:: error:: { UError , UResult , USimpleError } ;
18+ use uucore:: error:: { UError , UResult , USimpleError , strip_errno } ;
1919use uucore:: { format_usage, show, translate} ;
2020
2121// short types for switching interning behavior on the fly.
@@ -102,7 +102,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
102102 process_input ( reader, & mut g) ?;
103103 }
104104
105- g. run_tsort ( ) . map_err ( |e| USimpleError :: new ( 1 , format ! ( "write error: {e}" ) ) ) ?;
105+ g. run_tsort ( ) ?;
106106 Ok ( ( ) )
107107}
108108
@@ -151,6 +151,12 @@ enum TsortError {
151151 /// Wrapper for bubbling up IO errors
152152 #[ error( "{0}" ) ]
153153 IO ( #[ from] io:: Error ) ,
154+ /// Read error.
155+ #[ error( "{}" , translate!( "tsort-error-read" , "error" => strip_errno( . 0 ) ) ) ]
156+ Read ( io:: Error ) ,
157+ /// Write error.
158+ #[ error( "{}" , translate!( "tsort-error-write" , "error" => strip_errno( . 0 ) ) ) ]
159+ Write ( io:: Error ) ,
154160}
155161
156162// Auxiliary struct, just for printing loop nodes via show! macro
@@ -173,7 +179,7 @@ fn process_input<R: BufRead>(reader: R, graph: &mut Graph) -> Result<(), TsortEr
173179 if e. kind ( ) == io:: ErrorKind :: IsADirectory {
174180 TsortError :: IsDir ( graph. name ( ) )
175181 } else {
176- e . into ( )
182+ TsortError :: Read ( e )
177183 }
178184 } ) ?;
179185 for token in line. split_whitespace ( ) {
@@ -276,7 +282,7 @@ impl Graph {
276282 }
277283
278284 /// Implementation of algorithm T from TAOCP (Don. Knuth), vol. 1.
279- fn run_tsort ( & mut self ) -> io :: Result < ( ) > {
285+ fn run_tsort ( & mut self ) -> Result < ( ) , TsortError > {
280286 let mut independent_nodes_queue: VecDeque < Sym > = self
281287 . nodes
282288 . iter ( )
@@ -321,7 +327,7 @@ impl Graph {
321327 }
322328 }
323329
324- res
330+ res. map_err ( TsortError :: Write )
325331 }
326332 pub fn indegree ( & self , sym : Sym ) -> Option < usize > {
327333 self . nodes . get ( & sym) . map ( |data| data. predecessor_count )
0 commit comments