3
3
4
4
//! Tag
5
5
6
- use std :: fmt;
7
- use std :: num:: ParseIntError ;
8
- use std :: str:: FromStr ;
6
+ use core :: fmt;
7
+ use core :: num:: ParseIntError ;
8
+ use core :: str:: FromStr ;
9
9
10
10
use secp256k1:: schnorr:: Signature ;
11
11
use secp256k1:: XOnlyPublicKey ;
@@ -14,48 +14,99 @@ use serde::ser::SerializeSeq;
14
14
use serde:: { Deserialize , Deserializer , Serialize , Serializer } ;
15
15
16
16
use super :: id:: { self , EventId } ;
17
- use crate :: nips:: nip26:: Conditions ;
17
+ use crate :: nips:: nip26:: { Conditions , Error as Nip26Error } ;
18
18
use crate :: { Kind , Timestamp , UncheckedUrl } ;
19
19
20
20
/// [`Tag`] error
21
- #[ derive( Debug , thiserror :: Error ) ]
21
+ #[ derive( Debug ) ]
22
22
pub enum Error {
23
23
/// Impossible to parse [`Marker`]
24
- #[ error( "impossible to parse marker" ) ]
25
24
MarkerParseError ,
26
25
/// Unknown [`Report`]
27
- #[ error( "unknown report type" ) ]
28
26
UnknownReportType ,
29
27
/// Impossible to find tag kind
30
- #[ error( "impossible to find tag kind" ) ]
31
28
KindNotFound ,
32
29
/// Invalid length
33
- #[ error( "invalid length" ) ]
34
30
InvalidLength ,
31
+ /// Invalid Zap Request
32
+ InvalidZapRequest ,
35
33
/// Impossible to parse integer
36
- #[ error( transparent) ]
37
- ParseIntError ( #[ from] ParseIntError ) ,
34
+ ParseIntError ( ParseIntError ) ,
38
35
/// Secp256k1
39
- #[ error( transparent) ]
40
- Secp256k1 ( #[ from] secp256k1:: Error ) ,
36
+ Secp256k1 ( secp256k1:: Error ) ,
41
37
/// Hex decoding error
42
- #[ error( transparent) ]
43
- Hex ( #[ from] bitcoin_hashes:: hex:: Error ) ,
38
+ Hex ( bitcoin_hashes:: hex:: Error ) ,
44
39
/// Url parse error
45
- #[ error( "invalid url: {0}" ) ]
46
- Url ( #[ from] url:: ParseError ) ,
40
+ Url ( url:: ParseError ) ,
47
41
/// EventId error
48
- #[ error( transparent) ]
49
- EventId ( #[ from] id:: Error ) ,
42
+ EventId ( id:: Error ) ,
50
43
/// NIP26 error
51
- #[ error( transparent) ]
52
- Nip26 ( #[ from] crate :: nips:: nip26:: Error ) ,
44
+ NIP26 ( Nip26Error ) ,
53
45
/// Event Error
54
- #[ error( transparent) ]
55
- Event ( #[ from] crate :: event:: Error ) ,
56
- /// Invalid Zap Request
57
- #[ error( "Invalid Zap request" ) ]
58
- InvalidZapRequest ,
46
+ Event ( crate :: event:: Error ) ,
47
+ }
48
+
49
+ impl std:: error:: Error for Error { }
50
+
51
+ impl fmt:: Display for Error {
52
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
53
+ match self {
54
+ Self :: MarkerParseError => write ! ( f, "impossible to parse marker" ) ,
55
+ Self :: UnknownReportType => write ! ( f, "unknown report type" ) ,
56
+ Self :: KindNotFound => write ! ( f, "impossible to find tag kind" ) ,
57
+ Self :: InvalidLength => write ! ( f, "invalid length" ) ,
58
+ Self :: InvalidZapRequest => write ! ( f, "invalid Zap request" ) ,
59
+ Self :: ParseIntError ( e) => write ! ( f, "{e}" ) ,
60
+ Self :: Secp256k1 ( e) => write ! ( f, "{e}" ) ,
61
+ Self :: Hex ( e) => write ! ( f, "{e}" ) ,
62
+ Self :: Url ( e) => write ! ( f, "{e}" ) ,
63
+ Self :: EventId ( e) => write ! ( f, "{e}" ) ,
64
+ Self :: NIP26 ( e) => write ! ( f, "{e}" ) ,
65
+ Self :: Event ( e) => write ! ( f, "{e}" ) ,
66
+ }
67
+ }
68
+ }
69
+
70
+ impl From < ParseIntError > for Error {
71
+ fn from ( e : ParseIntError ) -> Self {
72
+ Self :: ParseIntError ( e)
73
+ }
74
+ }
75
+
76
+ impl From < secp256k1:: Error > for Error {
77
+ fn from ( e : secp256k1:: Error ) -> Self {
78
+ Self :: Secp256k1 ( e)
79
+ }
80
+ }
81
+
82
+ impl From < bitcoin_hashes:: hex:: Error > for Error {
83
+ fn from ( e : bitcoin_hashes:: hex:: Error ) -> Self {
84
+ Self :: Hex ( e)
85
+ }
86
+ }
87
+
88
+ impl From < url:: ParseError > for Error {
89
+ fn from ( e : url:: ParseError ) -> Self {
90
+ Self :: Url ( e)
91
+ }
92
+ }
93
+
94
+ impl From < id:: Error > for Error {
95
+ fn from ( e : id:: Error ) -> Self {
96
+ Self :: EventId ( e)
97
+ }
98
+ }
99
+
100
+ impl From < Nip26Error > for Error {
101
+ fn from ( e : Nip26Error ) -> Self {
102
+ Self :: NIP26 ( e)
103
+ }
104
+ }
105
+
106
+ impl From < crate :: event:: Error > for Error {
107
+ fn from ( e : crate :: event:: Error ) -> Self {
108
+ Self :: Event ( e)
109
+ }
59
110
}
60
111
61
112
/// Marker
0 commit comments