rustywallet_descriptor/
error.rs1use thiserror::Error;
4
5#[derive(Error, Debug, Clone, PartialEq, Eq)]
7pub enum DescriptorError {
8 #[error("Invalid descriptor syntax at position {position}: {message}")]
10 ParseError {
11 position: usize,
13 message: String,
15 },
16
17 #[error("Invalid checksum: expected {expected}, got {got}")]
19 InvalidChecksum {
20 expected: String,
22 got: String,
24 },
25
26 #[error("Missing checksum")]
28 MissingChecksum,
29
30 #[error("Invalid key: {0}")]
32 InvalidKey(String),
33
34 #[error("Invalid public key: {0}")]
36 InvalidPublicKey(String),
37
38 #[error("Invalid extended key: {0}")]
40 InvalidExtendedKey(String),
41
42 #[error("Invalid derivation path: {0}")]
44 InvalidDerivationPath(String),
45
46 #[error("Invalid fingerprint: {0}")]
48 InvalidFingerprint(String),
49
50 #[error("Invalid threshold: k={k} but n={n}")]
52 InvalidThreshold {
53 k: usize,
55 n: usize,
57 },
58
59 #[error("Unsupported descriptor type: {0}")]
61 UnsupportedType(String),
62
63 #[error("Wildcard not allowed in this context")]
65 WildcardNotAllowed,
66
67 #[error("Derivation index out of range: {0}")]
69 IndexOutOfRange(u32),
70
71 #[error("HD derivation error: {0}")]
73 DerivationError(String),
74
75 #[error("Address generation error: {0}")]
77 AddressError(String),
78
79 #[error("Script generation error: {0}")]
81 ScriptError(String),
82
83 #[error("Empty descriptor")]
85 EmptyDescriptor,
86
87 #[error("Unexpected end of input")]
89 UnexpectedEnd,
90
91 #[error("Unexpected character '{0}' at position {1}")]
93 UnexpectedChar(char, usize),
94}
95
96impl DescriptorError {
97 pub fn parse_error(position: usize, message: impl Into<String>) -> Self {
99 Self::ParseError {
100 position,
101 message: message.into(),
102 }
103 }
104}