@@ -6,7 +6,6 @@ use std::path::PathBuf;
66use std:: process;
77
88use clap:: Parser ;
9- use error_chain:: ChainedError ;
109use futures:: { future, StreamExt } ;
1110use nix_index:: files:: { FileNode , FileType } ;
1211use nix_index:: hydra:: Fetcher ;
@@ -16,9 +15,11 @@ use rusqlite::Connection;
1615
1716/// The main function of this module: creates a new command-not-found database.
1817async fn update_index ( args : & Args ) -> Result < ( ) > {
19- let fetcher = Fetcher :: new ( CACHE_URL . to_string ( ) ) . map_err ( ErrorKind :: ParseProxy ) ?;
20- let connection =
21- Connection :: open_in_memory ( ) . map_err ( |_| ErrorKind :: CreateDatabase ( args. output . clone ( ) ) ) ?;
18+ let fetcher = Fetcher :: new ( CACHE_URL . to_string ( ) ) . map_err ( Error :: ParseProxy ) ?;
19+ let connection = Connection :: open_in_memory ( ) . map_err ( |e| Error :: CreateDatabase {
20+ path : args. output . clone ( ) ,
21+ source : Box :: new ( e) ,
22+ } ) ?;
2223
2324 connection
2425 . execute (
@@ -32,10 +33,15 @@ async fn update_index(args: &Args) -> Result<()> {
3233 "# ,
3334 ( ) ,
3435 )
35- . map_err ( |_| ErrorKind :: CreateDatabase ( args. output . clone ( ) ) ) ?;
36-
37- let debug_connection = Connection :: open_in_memory ( )
38- . map_err ( |_| ErrorKind :: CreateDatabase ( args. debug_output . clone ( ) ) ) ?;
36+ . map_err ( |e| Error :: CreateDatabase {
37+ path : args. output . clone ( ) ,
38+ source : Box :: new ( e) ,
39+ } ) ?;
40+
41+ let debug_connection = Connection :: open_in_memory ( ) . map_err ( |e| Error :: CreateDatabase {
42+ path : args. debug_output . clone ( ) ,
43+ source : Box :: new ( e) ,
44+ } ) ?;
3945 debug_connection
4046 . execute (
4147 r#"
@@ -48,7 +54,10 @@ async fn update_index(args: &Args) -> Result<()> {
4854 "# ,
4955 ( ) ,
5056 )
51- . map_err ( |_| ErrorKind :: CreateDatabase ( args. debug_output . clone ( ) ) ) ?;
57+ . map_err ( |e| Error :: CreateDatabase {
58+ path : args. debug_output . clone ( ) ,
59+ source : Box :: new ( e) ,
60+ } ) ?;
5261
5362 let systems = match & args. systems {
5463 Some ( systems) => systems. iter ( ) . map ( |x| Some ( x. as_str ( ) ) ) . collect ( ) ,
@@ -62,7 +71,7 @@ async fn update_index(args: &Args) -> Result<()> {
6271 // Treat request errors as if the file list were missing
6372 let files = files. map ( |r| {
6473 r. unwrap_or_else ( |e| {
65- eprint ! ( "\n {}" , e. display_chain ( ) ) ;
74+ eprint ! ( "\n {:? }" , e) ;
6675 None
6776 } )
6877 } ) ;
@@ -117,7 +126,7 @@ async fn update_index(args: &Args) -> Result<()> {
117126 "insert or replace into Programs(name, system, package) values (?, ?, ?)" ,
118127 ( binary, system, attr) ,
119128 )
120- . map_err ( |_| ErrorKind :: CreateDatabase ( args. output . clone ( ) ) ) ?;
129+ . map_err ( |e| Error :: CreateDatabase { path : args. output . clone ( ) , source : Box :: new ( e ) } ) ?;
121130 }
122131
123132 if let Ok ( debuginfo) = path. strip_prefix ( "/lib/debug/.build-id" ) {
@@ -139,7 +148,7 @@ async fn update_index(args: &Args) -> Result<()> {
139148 "insert or replace into DebugInfo(build_id, url, filename) values (?, ?, ?)" ,
140149 ( build_id, format ! ( "../{}" , nar) , path. to_string_lossy ( ) . strip_prefix ( '/' ) ) ,
141150 )
142- . map_err ( |_| ErrorKind :: CreateDatabase ( args. debug_output . clone ( ) ) ) ?;
151+ . map_err ( |e| Error :: CreateDatabase { path : args. debug_output . clone ( ) , source : Box :: new ( e ) } ) ?;
143152 }
144153 }
145154 }
@@ -150,11 +159,17 @@ async fn update_index(args: &Args) -> Result<()> {
150159
151160 connection
152161 . backup ( "main" , & args. output , None )
153- . map_err ( |_| ErrorKind :: CreateDatabase ( args. output . clone ( ) ) ) ?;
162+ . map_err ( |e| Error :: CreateDatabase {
163+ path : args. output . clone ( ) ,
164+ source : Box :: new ( e) ,
165+ } ) ?;
154166
155167 debug_connection
156168 . backup ( "main" , & args. debug_output , None )
157- . map_err ( |_| ErrorKind :: CreateDatabase ( args. debug_output . clone ( ) ) ) ?;
169+ . map_err ( |e| Error :: CreateDatabase {
170+ path : args. debug_output . clone ( ) ,
171+ source : Box :: new ( e) ,
172+ } ) ?;
158173
159174 Ok ( ( ) )
160175}
@@ -192,15 +207,7 @@ async fn main() {
192207 let args = Args :: parse ( ) ;
193208
194209 if let Err ( e) = update_index ( & args) . await {
195- eprintln ! ( "error: {}" , e) ;
196-
197- for e in e. iter ( ) . skip ( 1 ) {
198- eprintln ! ( "caused by: {}" , e) ;
199- }
200-
201- if let Some ( backtrace) = e. backtrace ( ) {
202- eprintln ! ( "backtrace: {:?}" , backtrace) ;
203- }
210+ eprintln ! ( "error: {:?}" , e) ;
204211 process:: exit ( 2 ) ;
205212 }
206213}
0 commit comments