pub struct GitwayError { /* private fields */ }Expand description
The single error type returned by all gitway-lib operations.
Provides is_* predicate methods so callers can branch on error categories
without depending on internal representation. A Backtrace is captured
automatically; it is rendered via std::fmt::Display when
RUST_BACKTRACE=1 is set.
§Predicates
| Method | Condition |
|---|---|
is_io | Underlying I/O failure |
is_host_key_mismatch | Server key does not match pinned fingerprints |
is_authentication_failed | Server rejected our key |
is_no_key_found | No identity key available |
is_key_encrypted | Key file needs a passphrase |
Implementations§
Source§impl GitwayError
impl GitwayError
Sourcepub fn with_hint(self, hint: impl Into<String>) -> Self
pub fn with_hint(self, hint: impl Into<String>) -> Self
Attaches a context-specific hint that supersedes the kind-level
default returned by hint.
Use this at call sites where the caller knows exactly what the
user should do next — much more useful than a generic “run
gitway --help”.
§Example
use gitway_lib::GitwayError;
let e = GitwayError::invalid_config("no such host: github.com.invalid")
.with_hint("Check the hostname for typos, or run `gitway --test <host>` to confirm reachability");
assert!(e.hint().contains("typos"));pub fn host_key_mismatch(fingerprint: impl Into<String>) -> Self
pub fn authentication_failed() -> Self
pub fn no_key_found() -> Self
pub fn invalid_config(message: impl Into<String>) -> Self
Sourcepub fn signing(message: impl Into<String>) -> Self
pub fn signing(message: impl Into<String>) -> Self
Signals that SSH signature production failed.
Mapped to exit code 1 (GENERAL_ERROR).
Sourcepub fn signature_invalid(reason: impl Into<String>) -> Self
pub fn signature_invalid(reason: impl Into<String>) -> Self
Signals that SSH signature verification failed.
Mapped to exit code 4 (PERMISSION_DENIED) to match git’s treatment
of a non-zero ssh-keygen -Y verify as an authentication-class failure.
Sourcepub fn is_host_key_mismatch(&self) -> bool
pub fn is_host_key_mismatch(&self) -> bool
Returns true if the server’s host key did not match any pinned fingerprint.
Sourcepub fn is_authentication_failed(&self) -> bool
pub fn is_authentication_failed(&self) -> bool
Returns true if the server rejected our public-key authentication attempt.
Sourcepub fn is_no_key_found(&self) -> bool
pub fn is_no_key_found(&self) -> bool
Returns true if no usable identity key was found.
Sourcepub fn is_key_encrypted(&self) -> bool
pub fn is_key_encrypted(&self) -> bool
Returns true if a key file was found but requires a passphrase to decrypt.
Sourcepub fn fingerprint(&self) -> Option<&str>
pub fn fingerprint(&self) -> Option<&str>
Returns the path at which an encrypted key was found, if applicable.
Sourcepub fn error_code(&self) -> &'static str
pub fn error_code(&self) -> &'static str
Returns an upper-snake-case error code for structured JSON output (SFRS Rule 5).
| Code | Exit code | Condition |
|---|---|---|
GENERAL_ERROR | 1 | I/O, SSH protocol, or key-parsing failure |
USAGE_ERROR | 2 | Invalid configuration or bad arguments |
NOT_FOUND | 3 | No identity key found |
PERMISSION_DENIED | 4 | Host key mismatch or authentication failure |
Sourcepub fn exit_code(&self) -> u32
pub fn exit_code(&self) -> u32
Returns the numeric process exit code for this error (SFRS Rule 2).
| Code | Meaning |
|---|---|
| 1 | General / unexpected error |
| 2 | Usage error (bad arguments, invalid configuration) |
| 3 | Not found (no identity key, unknown host) |
| 4 | Permission denied (authentication failure, host key mismatch) |
Sourcepub fn hint(&self) -> &str
pub fn hint(&self) -> &str
Returns a short “what to do next” line for the user.
Call-site-specific hints attached via with_hint
take priority. Otherwise the kind-level default is returned —
these are deliberately phrased in plain English and prescriptive
voice (tell the reader what to type, not what went wrong; the
Display output already says what went wrong).
Emitted on stderr after the error message in human mode, and
carried as the hint field in --json output (SFRS Rule 5).
Trait Implementations§
Source§impl Debug for GitwayError
impl Debug for GitwayError
Source§impl Display for GitwayError
impl Display for GitwayError
Source§impl Error for GitwayError
impl Error for GitwayError
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()