1- use thiserror:: Error ;
2-
31/// PostgreSQL archive result type
4- pub type Result < T , E = ArchiveError > = core:: result:: Result < T , E > ;
2+ pub type Result < T , E = Error > = core:: result:: Result < T , E > ;
53
64/// PostgreSQL archive errors
7- #[ derive( Debug , Error ) ]
8- pub enum ArchiveError {
5+ #[ derive( Debug , thiserror :: Error ) ]
6+ pub enum Error {
97 /// Asset not found
108 #[ error( "asset [{0}] not found" ) ]
119 AssetNotFound ( String ) ,
@@ -29,45 +27,45 @@ pub enum ArchiveError {
2927 Unexpected ( String ) ,
3028}
3129
32- /// Converts a [`regex::Error`] into an [`ParseError`](ArchiveError ::ParseError)
33- impl From < regex:: Error > for ArchiveError {
30+ /// Converts a [`regex::Error`] into an [`ParseError`](Error ::ParseError)
31+ impl From < regex:: Error > for Error {
3432 fn from ( error : regex:: Error ) -> Self {
35- ArchiveError :: ParseError ( error. into ( ) )
33+ Error :: ParseError ( error. into ( ) )
3634 }
3735}
3836
39- /// Converts a [`reqwest::Error`] into an [`IoError`](ArchiveError ::IoError)
40- impl From < reqwest:: Error > for ArchiveError {
37+ /// Converts a [`reqwest::Error`] into an [`IoError`](Error ::IoError)
38+ impl From < reqwest:: Error > for Error {
4139 fn from ( error : reqwest:: Error ) -> Self {
42- ArchiveError :: IoError ( error. into ( ) )
40+ Error :: IoError ( error. into ( ) )
4341 }
4442}
4543
46- /// Converts a [`std::io::Error`] into an [`IoError`](ArchiveError ::IoError)
47- impl From < std:: io:: Error > for ArchiveError {
44+ /// Converts a [`std::io::Error`] into an [`IoError`](Error ::IoError)
45+ impl From < std:: io:: Error > for Error {
4846 fn from ( error : std:: io:: Error ) -> Self {
49- ArchiveError :: IoError ( error. into ( ) )
47+ Error :: IoError ( error. into ( ) )
5048 }
5149}
5250
53- /// Converts a [`std::num::ParseIntError`] into an [`ParseError`](ArchiveError ::ParseError)
54- impl From < std:: num:: ParseIntError > for ArchiveError {
51+ /// Converts a [`std::num::ParseIntError`] into an [`ParseError`](Error ::ParseError)
52+ impl From < std:: num:: ParseIntError > for Error {
5553 fn from ( error : std:: num:: ParseIntError ) -> Self {
56- ArchiveError :: ParseError ( error. into ( ) )
54+ Error :: ParseError ( error. into ( ) )
5755 }
5856}
5957
60- /// Converts a [`std::path::StripPrefixError`] into an [`ParseError`](ArchiveError ::ParseError)
61- impl From < std:: path:: StripPrefixError > for ArchiveError {
58+ /// Converts a [`std::path::StripPrefixError`] into an [`ParseError`](Error ::ParseError)
59+ impl From < std:: path:: StripPrefixError > for Error {
6260 fn from ( error : std:: path:: StripPrefixError ) -> Self {
63- ArchiveError :: ParseError ( error. into ( ) )
61+ Error :: ParseError ( error. into ( ) )
6462 }
6563}
6664
67- /// Converts a [`anyhow::Error`] into an [`Unexpected`](ArchiveError ::Unexpected)
68- impl From < anyhow:: Error > for ArchiveError {
65+ /// Converts a [`anyhow::Error`] into an [`Unexpected`](Error ::Unexpected)
66+ impl From < anyhow:: Error > for Error {
6967 fn from ( error : anyhow:: Error ) -> Self {
70- ArchiveError :: Unexpected ( error. to_string ( ) )
68+ Error :: Unexpected ( error. to_string ( ) )
7169 }
7270}
7371
@@ -82,7 +80,7 @@ mod test {
8280 #[ test]
8381 fn test_from_regex_error ( ) {
8482 let regex_error = regex:: Error :: Syntax ( "test" . to_string ( ) ) ;
85- let error = ArchiveError :: from ( regex_error) ;
83+ let error = Error :: from ( regex_error) ;
8684 assert_eq ! ( error. to_string( ) , "test" ) ;
8785 }
8886
@@ -91,15 +89,15 @@ mod test {
9189 let result = reqwest:: get ( "https://a.com" ) . await ;
9290 assert ! ( result. is_err( ) ) ;
9391 if let Err ( error) = result {
94- let error = ArchiveError :: from ( error) ;
92+ let error = Error :: from ( error) ;
9593 assert ! ( error. to_string( ) . contains( "https://a.com" ) ) ;
9694 }
9795 }
9896
9997 #[ test]
10098 fn test_from_io_error ( ) {
10199 let io_error = std:: io:: Error :: new ( std:: io:: ErrorKind :: NotFound , "test" ) ;
102- let error = ArchiveError :: from ( io_error) ;
100+ let error = Error :: from ( io_error) ;
103101 assert_eq ! ( error. to_string( ) , "test" ) ;
104102 }
105103
@@ -108,7 +106,7 @@ mod test {
108106 let result = u64:: from_str ( "test" ) ;
109107 assert ! ( result. is_err( ) ) ;
110108 if let Err ( error) = result {
111- let error = ArchiveError :: from ( error) ;
109+ let error = Error :: from ( error) ;
112110 assert_eq ! ( error. to_string( ) , "invalid digit found in string" ) ;
113111 }
114112 }
@@ -119,15 +117,15 @@ mod test {
119117 let result = path. strip_prefix ( "foo" ) ;
120118 assert ! ( result. is_err( ) ) ;
121119 if let Err ( error) = result {
122- let error = ArchiveError :: from ( error) ;
120+ let error = Error :: from ( error) ;
123121 assert_eq ! ( error. to_string( ) , "prefix not found" ) ;
124122 }
125123 }
126124
127125 #[ test]
128126 fn test_from_anyhow_error ( ) {
129127 let anyhow_error = anyhow:: Error :: msg ( "test" ) ;
130- let error = ArchiveError :: from ( anyhow_error) ;
128+ let error = Error :: from ( anyhow_error) ;
131129 assert_eq ! ( error. to_string( ) , "test" ) ;
132130 }
133131}
0 commit comments