Skip to main content

bolt12_common/
error.rs

1use serde::Serialize;
2use thiserror::Error;
3
4/// Machine-readable failure from decode or argument validation.
5#[derive(Debug, Clone, PartialEq, Eq, Error, Serialize)]
6#[error("{kind}: {message}")]
7pub struct Error {
8    #[serde(rename = "error")]
9    pub kind: ErrorKind,
10    pub message: String,
11}
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Error, Serialize)]
14#[serde(rename_all = "snake_case")]
15pub enum ErrorKind {
16    #[error("unknown_hrp")]
17    UnknownHrp,
18    #[error("invalid_argument")]
19    InvalidArgument,
20    #[error("decode_failed")]
21    DecodeFailed,
22}
23
24impl Error {
25    pub fn new(kind: ErrorKind, message: impl Into<String>) -> Self {
26        Self {
27            kind,
28            message: message.into(),
29        }
30    }
31}