X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Futil%2Ferrors.rs;h=9446b35854baf9e34f665d3e1755ab7f599c4992;hb=ed30a199e35070c85fdf8199ec4ea65bcbec9a47;hp=0700b451c670d67fce74d0a4f3f42a9b2554dacf;hpb=4553369d2049b2995c664ef7690318a45031788c;p=rust-lightning diff --git a/src/util/errors.rs b/src/util/errors.rs index 0700b451..9446b358 100644 --- a/src/util/errors.rs +++ b/src/util/errors.rs @@ -1,15 +1,47 @@ +//! Error types live here. + use std::fmt; +/// Indicates an error on the client's part (usually some variant of attempting to use too-low or +/// too-high values) pub enum APIError { - APIMisuseError {err: &'static str}, - FeeRateTooHigh {err: String, feerate: u64}, + /// 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. + APIMisuseError { + /// A human-readable error message + err: &'static str + }, + /// 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. + FeeRateTooHigh { + /// A human-readable error message + err: String, + /// The feerate which was too high. + feerate: u64 + }, + /// A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route, + /// too-many-hops, etc). + RouteError { + /// A human-readable error message + err: &'static str + }, + /// 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. + ChannelUnavailable { + /// A human-readable error message + err: &'static str + } } impl fmt::Debug for APIError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { APIError::APIMisuseError {ref err} => f.write_str(err), - APIError::FeeRateTooHigh {ref err, ref feerate} => write!(f, "{} feerate: {}", err, feerate) + APIError::FeeRateTooHigh {ref err, ref feerate} => write!(f, "{} feerate: {}", err, feerate), + APIError::RouteError {ref err} => f.write_str(err), + APIError::ChannelUnavailable {ref err} => f.write_str(err), } - } + } }