File tree Expand file tree Collapse file tree 5 files changed +19
-29
lines changed Expand file tree Collapse file tree 5 files changed +19
-29
lines changed Original file line number Diff line number Diff line change @@ -5,11 +5,5 @@ use thiserror::Error;
5
5
pub enum ContractError {
6
6
#[ error( "{0}" ) ]
7
7
/// this is needed so we can use `bucket.load(...)?` and have it auto-converted to the custom error
8
- Std ( StdError ) ,
9
- }
10
-
11
- impl From < StdError > for ContractError {
12
- fn from ( err : StdError ) -> Self {
13
- Self :: Std ( err)
14
- }
8
+ Std ( #[ from] StdError ) ,
15
9
}
Original file line number Diff line number Diff line change @@ -5,17 +5,11 @@ use thiserror::Error;
5
5
pub enum HackError {
6
6
#[ error( "{0}" ) ]
7
7
/// this is needed so we can use `bucket.load(...)?` and have it auto-converted to the custom error
8
- Std ( StdError ) ,
8
+ Std ( # [ from ] StdError ) ,
9
9
// this is whatever we want
10
10
#[ error( "Unauthorized" ) ]
11
11
Unauthorized { } ,
12
12
// this is whatever we want
13
13
#[ error( "Downgrade is not supported" ) ]
14
14
Downgrade ,
15
15
}
16
-
17
- impl From < StdError > for HackError {
18
- fn from ( err : StdError ) -> Self {
19
- Self :: Std ( err)
20
- }
21
- }
Original file line number Diff line number Diff line change @@ -5,16 +5,10 @@ use thiserror::Error;
5
5
pub enum ReflectError {
6
6
#[ error( "{0}" ) ]
7
7
// let thiserror implement From<StdError> for you
8
- Std ( StdError ) ,
8
+ Std ( # [ from ] StdError ) ,
9
9
// this is whatever we want
10
10
#[ error( "Permission denied: the sender is not the current owner" ) ]
11
11
NotCurrentOwner { expected : String , actual : String } ,
12
12
#[ error( "Messages empty. Must reflect at least one message" ) ]
13
13
MessagesEmpty ,
14
14
}
15
-
16
- impl From < StdError > for ReflectError {
17
- fn from ( err : StdError ) -> Self {
18
- Self :: Std ( err)
19
- }
20
- }
Original file line number Diff line number Diff line change @@ -5,13 +5,7 @@ use thiserror::Error;
5
5
pub enum ContractError {
6
6
#[ error( "{0}" ) ]
7
7
/// this is needed so we can use `bucket.load(...)?` and have it auto-converted to the custom error
8
- Std ( StdError ) ,
8
+ Std ( # [ from ] StdError ) ,
9
9
#[ error( "{0}" ) ]
10
10
Instantiate2Address ( #[ from] Instantiate2AddressError ) ,
11
11
}
12
-
13
- impl From < StdError > for ContractError {
14
- fn from ( err : StdError ) -> Self {
15
- Self :: Std ( err)
16
- }
17
- }
Original file line number Diff line number Diff line change 1
1
use alloc:: string:: ToString ;
2
2
use core:: fmt;
3
- use std:: { error:: Error , str, string} ;
3
+ use std:: { error:: Error , ops :: Deref , str, string} ;
4
4
5
5
use super :: BT ;
6
6
@@ -58,6 +58,14 @@ impl AsRef<dyn Error + Send + Sync> for StdError {
58
58
}
59
59
}
60
60
61
+ impl Deref for StdError {
62
+ type Target = dyn Error + Send + Sync ;
63
+
64
+ fn deref ( & self ) -> & Self :: Target {
65
+ & * self . 0 . inner
66
+ }
67
+ }
68
+
61
69
impl StdError {
62
70
pub fn msg < D > ( msg : D ) -> Self
63
71
where
@@ -294,6 +302,12 @@ mod tests {
294
302
use core:: str;
295
303
use std:: string;
296
304
305
+ #[ derive( Debug , thiserror:: Error ) ]
306
+ enum AssertThiserrorWorks {
307
+ #[ error( transparent) ]
308
+ Std ( #[ from] StdError ) ,
309
+ }
310
+
297
311
#[ test]
298
312
fn implements_debug ( ) {
299
313
let error: StdError = StdError :: from ( OverflowError :: new ( OverflowOperation :: Sub ) ) ;
You can’t perform that action at this time.
0 commit comments