2018-09-19 17:39:43 -04:00
|
|
|
//! Error types live here.
|
|
|
|
|
2018-08-17 12:46:17 +09:00
|
|
|
use std::fmt;
|
|
|
|
|
2018-08-17 14:29:16 -04:00
|
|
|
/// Indicates an error on the client's part (usually some variant of attempting to use too-low or
|
|
|
|
/// too-high values)
|
2018-08-17 12:46:17 +09:00
|
|
|
pub enum APIError {
|
2018-08-17 14:29:16 -04:00
|
|
|
/// Indicates the API was wholly misused (see err for more). Cases where these can be returned
|
|
|
|
/// are documented, but generally indicates some precondition of a function was violated.
|
2018-09-19 17:39:43 -04:00
|
|
|
APIMisuseError {
|
|
|
|
/// A human-readable error message
|
|
|
|
err: &'static str
|
|
|
|
},
|
2018-08-17 14:29:16 -04:00
|
|
|
/// Due to a high feerate, we were unable to complete the request.
|
|
|
|
/// For example, this may be returned if the feerate implies we cannot open a channel at the
|
|
|
|
/// requested value, but opening a larger channel would succeed.
|
2018-09-19 17:39:43 -04:00
|
|
|
FeeRateTooHigh {
|
|
|
|
/// A human-readable error message
|
|
|
|
err: String,
|
|
|
|
/// The feerate which was too high.
|
|
|
|
feerate: u64
|
|
|
|
},
|
2018-10-15 08:55:19 -04:00
|
|
|
/// A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route,
|
|
|
|
/// too-many-hops, etc).
|
2018-09-19 17:39:43 -04:00
|
|
|
RouteError {
|
|
|
|
/// A human-readable error message
|
|
|
|
err: &'static str
|
|
|
|
},
|
2018-10-15 08:55:19 -04:00
|
|
|
/// We were unable to complete the request as the Channel required to do so is unable to
|
|
|
|
/// complete the request (or was not found). This can take many forms, including disconnected
|
|
|
|
/// peer, channel at capacity, channel shutting down, etc.
|
2018-09-27 12:58:05 +09:00
|
|
|
ChannelUnavailable {
|
|
|
|
/// A human-readable error message
|
|
|
|
err: &'static str
|
2018-10-17 18:21:06 -04:00
|
|
|
},
|
|
|
|
/// An attempt to call add_update_monitor returned an Err (ie you did this!), causing the
|
|
|
|
/// attempted action to fail.
|
|
|
|
MonitorUpdateFailed,
|
2018-08-17 12:46:17 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Debug for APIError {
|
2018-08-17 14:29:16 -04:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2018-08-17 12:46:17 +09:00
|
|
|
match *self {
|
|
|
|
APIError::APIMisuseError {ref err} => f.write_str(err),
|
2018-09-13 05:23:12 +09:00
|
|
|
APIError::FeeRateTooHigh {ref err, ref feerate} => write!(f, "{} feerate: {}", err, feerate),
|
|
|
|
APIError::RouteError {ref err} => f.write_str(err),
|
2018-09-27 12:58:05 +09:00
|
|
|
APIError::ChannelUnavailable {ref err} => f.write_str(err),
|
2018-10-17 18:21:06 -04:00
|
|
|
APIError::MonitorUpdateFailed => f.write_str("Client indicated a channel monitor update failed"),
|
2018-08-17 12:46:17 +09:00
|
|
|
}
|
2018-08-17 14:29:16 -04:00
|
|
|
}
|
2018-08-17 12:46:17 +09:00
|
|
|
}
|