pub enum GithubError {
AuthenticationFailed,
AuthenticationLockout {
retry_after: Duration,
},
Forbidden {
method: String,
path: String,
message: Option<String>,
headers: Box<HeaderMap>,
},
Status {
status: u16,
method: String,
path: String,
message: Option<String>,
headers: Box<HeaderMap>,
},
Transport(Error),
Decode {
what: &'static str,
expected: &'static str,
source: Error,
},
Malformed {
what: &'static str,
value: String,
},
Config(ConfigError),
}Expand description
Everything AuthenticatedClient can fail with.
The first three variants are the taxonomy 03-control-flows.md flow 4.3
requires, and they are separate variants because c3 and f1 both act on
the distinction: GithubError::AuthenticationFailed moves a policy to
authentication_failed and tells the operator to run auth login,
GithubError::AuthenticationLockout must wait and tell the operator
nothing is wrong with their credential, and GithubError::Forbidden is a
permissions answer that re-authenticating will not change.
§Why the failing variants carry response headers
Rate-limit policy is c3’s and is deliberately not implemented here. But a
policy needs evidence, and the evidence — retry-after,
x-ratelimit-remaining, x-ratelimit-reset — only exists on the response
that failed. An error taxonomy that dropped those headers would leave c3
with no way to honour a 429 except by editing this file, which is exactly
the conflict the c2/c3 ownership split exists to prevent. So
GithubError::Status and GithubError::Forbidden carry the headers
verbatim and interpret none of them; see GithubError::headers.
Variants§
AuthenticationFailed
GitHub rejected the credential and a single re-validation confirmed it.
Terminal: only an interactive auth login clears this.
AuthenticationLockout
GitHub answered 403 after 401s — its temporary authentication
lockout, not a permissions change. Back off; do not re-authenticate and
do not retry.
Forbidden
A 403 that is not the lockout: a permissions answer, or GitHub’s own
rate limit. c3 tells the two apart from headers; this crate does not,
because which of them is worth retrying is rate-limit policy.
Fields
Status
Fields
Transport(Error)
The request never got an answer. The URL is stripped from the source error before it is stored: a device-flow URL never carries a secret, but stripping it costs nothing and removes a whole class of future leak.
Decode
Malformed
Config(ConfigError)
Implementations§
Source§impl GithubError
impl GithubError
Sourcepub fn is_authentication(&self) -> bool
pub fn is_authentication(&self) -> bool
true for the two authentication outcomes, which callers handle
differently from every other failure.
Sourcepub fn is_lockout(&self) -> bool
pub fn is_lockout(&self) -> bool
true only for the lockout, which is the one authentication outcome that
resolves by waiting rather than by signing in again.
Sourcepub fn headers(&self) -> Option<&HeaderMap>
pub fn headers(&self) -> Option<&HeaderMap>
The failing response’s headers, for the variants that have them.
This is the whole of c2’s contribution to rate limiting: it hands c3
the evidence and stops there. Nothing in this crate reads
x-ratelimit-remaining to decide anything.
Sourcepub fn retry_after(&self) -> Option<Duration>
pub fn retry_after(&self) -> Option<Duration>
The failing response’s retry-after, in seconds, if it sent one.
Reading a documented header is evidence, not policy: what to do with a
retry-after — wait, shed load, surface it to an operator — is c3’s.
Sourcepub fn rate_limit(&self) -> Option<RateLimitEvidence>
pub fn rate_limit(&self) -> Option<RateLimitEvidence>
The x-ratelimit-remaining / x-ratelimit-reset pair, when present.
Returned as the raw numbers GitHub sent. reset is a Unix timestamp in
seconds, which is what the header carries; it is deliberately not turned
into a Timestamp here, because comparing it against a clock is the
first step of a policy decision and that decision is c3’s.
Trait Implementations§
Source§impl Debug for GithubError
impl Debug for GithubError
Source§impl Display for GithubError
impl Display for GithubError
Source§impl Error for GithubError
impl Error for GithubError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()