use thiserror::Error;
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum DescriptorError {
#[error("Invalid descriptor syntax at position {position}: {message}")]
ParseError {
position: usize,
message: String,
},
#[error("Invalid checksum: expected {expected}, got {got}")]
InvalidChecksum {
expected: String,
got: String,
},
#[error("Missing checksum")]
MissingChecksum,
#[error("Invalid key: {0}")]
InvalidKey(String),
#[error("Invalid public key: {0}")]
InvalidPublicKey(String),
#[error("Invalid extended key: {0}")]
InvalidExtendedKey(String),
#[error("Invalid derivation path: {0}")]
InvalidDerivationPath(String),
#[error("Invalid fingerprint: {0}")]
InvalidFingerprint(String),
#[error("Invalid threshold: k={k} but n={n}")]
InvalidThreshold {
k: usize,
n: usize,
},
#[error("Unsupported descriptor type: {0}")]
UnsupportedType(String),
#[error("Wildcard not allowed in this context")]
WildcardNotAllowed,
#[error("Derivation index out of range: {0}")]
IndexOutOfRange(u32),
#[error("HD derivation error: {0}")]
DerivationError(String),
#[error("Address generation error: {0}")]
AddressError(String),
#[error("Script generation error: {0}")]
ScriptError(String),
#[error("Empty descriptor")]
EmptyDescriptor,
#[error("Unexpected end of input")]
UnexpectedEnd,
#[error("Unexpected character '{0}' at position {1}")]
UnexpectedChar(char, usize),
}
impl DescriptorError {
pub fn parse_error(position: usize, message: impl Into<String>) -> Self {
Self::ParseError {
position,
message: message.into(),
}
}
}