1- use std:: cell:: BorrowError ;
21use std:: ffi:: CString ;
3- use std:: ffi:: NulError ;
42use std:: fmt;
53use std:: os:: raw:: { c_char, c_int} ;
64use std:: ptr;
75
8- use serde_json:: Error as JSONError ;
9- use ssi:: error:: Error as SSIError ;
10- use std:: error:: Error as StdError ;
11- use std:: io:: Error as IOError ;
12- use std:: str:: Utf8Error ;
13-
146static UNKNOWN_ERROR : & str = "Unable to create error string\0 " ;
157
168use std:: cell:: RefCell ;
179thread_local ! {
1810 pub static LAST_ERROR : RefCell <Option <( i32 , CString ) >> = RefCell :: new( None ) ;
1911}
2012
21- #[ derive( Debug ) ]
13+ #[ derive( thiserror :: Error , Debug ) ]
2214pub enum Error {
23- SSI ( ssi:: error:: Error ) ,
24- Null ( NulError ) ,
25- Utf8 ( Utf8Error ) ,
26- Borrow ( BorrowError ) ,
27- IO ( IOError ) ,
15+ #[ error( transparent) ]
16+ VC ( #[ from] ssi:: vc:: Error ) ,
17+ #[ error( transparent) ]
18+ Zcap ( #[ from] ssi:: zcap:: Error ) ,
19+ #[ error( transparent) ]
20+ JWK ( #[ from] ssi:: jwk:: Error ) ,
21+ #[ error( transparent) ]
22+ Null ( #[ from] std:: ffi:: NulError ) ,
23+ #[ error( transparent) ]
24+ Utf8 ( #[ from] std:: str:: Utf8Error ) ,
25+ #[ error( transparent) ]
26+ Borrow ( #[ from] std:: cell:: BorrowError ) ,
27+ #[ error( transparent) ]
28+ IO ( #[ from] std:: io:: Error ) ,
29+ #[ error( "Unable to generate DID" ) ]
2830 UnableToGenerateDID ,
31+ #[ error( "Unknown DID method" ) ]
2932 UnknownDIDMethod ,
33+ #[ error( "Unable to get verification method" ) ]
3034 UnableToGetVerificationMethod ,
35+ #[ error( "Unknown proof format: {0}" ) ]
3136 UnknownProofFormat ( String ) ,
3237
3338 #[ doc( hidden) ]
39+ #[ error( "" ) ]
3440 __Nonexhaustive,
3541}
3642
@@ -47,16 +53,16 @@ impl Error {
4753 fn get_code ( & self ) -> c_int {
4854 // TODO: try to give each individual error its own number
4955 match self {
50- Error :: SSI ( _) => 1 ,
56+ Error :: VC ( _) => 1 ,
5157 Error :: Null ( _) => 2 ,
5258 Error :: Utf8 ( _) => 3 ,
59+ Error :: JWK ( _) => 4 ,
60+ Error :: Zcap ( _) => 5 ,
5361 _ => -1 ,
5462 }
5563 }
5664}
5765
58- impl StdError for Error { }
59-
6066#[ no_mangle]
6167/// Retrieve a human-readable description of the most recent error encountered by a DIDKit C
6268/// function. The returned string is valid until the next call to a DIDKit function in the current
@@ -84,54 +90,15 @@ pub extern "C" fn didkit_error_code() -> c_int {
8490 } )
8591}
8692
87- impl fmt:: Display for Error {
88- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
89- match self {
90- Error :: SSI ( e) => e. fmt ( f) ,
91- Error :: Null ( e) => e. fmt ( f) ,
92- Error :: Utf8 ( e) => e. fmt ( f) ,
93- Error :: UnableToGenerateDID => write ! ( f, "Unable to generate DID" ) ,
94- Error :: UnknownDIDMethod => write ! ( f, "Unknown DID method" ) ,
95- Error :: UnableToGetVerificationMethod => write ! ( f, "Unable to get verification method" ) ,
96- Error :: UnknownProofFormat ( format) => write ! ( f, "Unknown proof format: {}" , format) ,
97- _ => unreachable ! ( ) ,
98- }
99- }
100- }
101-
102- impl From < SSIError > for Error {
103- fn from ( err : SSIError ) -> Error {
104- Error :: SSI ( err)
105- }
106- }
107-
108- impl From < JSONError > for Error {
109- fn from ( err : JSONError ) -> Error {
110- Error :: SSI ( SSIError :: from ( err) )
111- }
112- }
113-
114- impl From < NulError > for Error {
115- fn from ( err : NulError ) -> Error {
116- Error :: Null ( err)
117- }
118- }
119-
120- impl From < Utf8Error > for Error {
121- fn from ( err : Utf8Error ) -> Error {
122- Error :: Utf8 ( err)
123- }
124- }
125-
126- impl From < IOError > for Error {
127- fn from ( err : IOError ) -> Error {
128- Error :: IO ( err)
93+ impl From < serde_json:: Error > for Error {
94+ fn from ( err : serde_json:: Error ) -> Error {
95+ Error :: VC ( ssi:: vc:: Error :: from ( err) )
12996 }
13097}
13198
132- impl From < BorrowError > for Error {
133- fn from ( err : BorrowError ) -> Error {
134- Error :: Borrow ( err )
99+ impl From < ssi :: ldp :: Error > for Error {
100+ fn from ( e : ssi :: ldp :: Error ) -> Error {
101+ ssi :: vc :: Error :: from ( e ) . into ( )
135102 }
136103}
137104
0 commit comments