pub enum XurlError {
Show 13 variants
Http(String),
Io(String),
InvalidMethod(String),
Api {
status: u16,
body: String,
},
Validation(String),
InvalidUrl(String),
InvalidPathParam {
name: String,
value: String,
},
Internal(String),
Json(String),
Auth(String),
TokenStore(String),
EnvelopeAlreadyEmitted {
exit_code: i32,
},
AuthMethodMismatch {
endpoint: String,
rendered_url: Option<String>,
method: String,
requested: Option<String>,
supported: Vec<String>,
available_in_app: Option<Vec<String>>,
app: Option<String>,
other_apps_with_creds: Option<Vec<String>>,
},
}Expand description
Top-level error type for xurl-rs.
result_large_err would fire because the largest variant
(AuthMethodMismatch) carries multiple String/Vec<String> fields.
Boxing the variant would change the public construction surface; allow
the lint on the enum so consumers can keep building the variant inline.
§Example
use xurl::error::XurlError;
match result {
Ok(()) => println!("ok"),
Err(XurlError::Api { status, body }) => eprintln!("api {status}: {body}"),
Err(XurlError::Validation(msg)) => eprintln!("validation: {msg}"),
Err(XurlError::InvalidUrl(url)) => eprintln!("bad URL: {url}"),
Err(other) => eprintln!("{} (kind={})", other, other.kind()),
}Variants§
Http(String)
HTTP transport / request construction error.
Io(String)
File / IO error.
InvalidMethod(String)
Invalid HTTP method supplied.
Api
API returned an HTTP error response (status >= 400).
Fields
Validation(String)
Non-HTTP validation or logic error (e.g., missing fields, errors-only 200 responses).
InvalidUrl(String)
Raw URL supplied with an unsupported scheme. Only http:// and
https:// are accepted; file/ftp/etc are rejected before any
network or filesystem activity.
InvalidPathParam
Path-parameter value contained a character that would break URL
semantics (/, ?, #, or %). Surfaces real IDs that contain
stray separators rather than silently encoding them.
Fields
Internal(String)
Internal invariant violated — typically a programmer error such as
a path template referencing a {name} segment that the caller never
supplied in path_params.
Json(String)
JSON serialization / deserialization error.
Auth(String)
Authentication error with sub-type context.
TokenStore(String)
Token store persistence / lookup error.
EnvelopeAlreadyEmitted
Sentinel: a structured envelope was already emitted by the call site.
The runner short-circuits its trailing print_error for this variant
and propagates the carried exit code unchanged. Used by
print_confirmation_required so the canonical envelope
{"status":"error","reason":"confirmation-required",…} is the only
thing the agent sees on stderr (no duplicated {"error":...,"kind":...}
from the generic print_error path).
AuthMethodMismatch
Auth method mismatch: the user supplied (or the auto-detect resolved) an auth method the endpoint’s matrix entry doesn’t accept.
Three shapes share the variant:
- Explicit-mismatch:
requested = Some("app"|"oauth1"|"oauth2"),available_in_app = None. The user passed--auth XandXisn’t in the endpoint’s supported set. - Empty-intersection:
requested = None,available_in_app = Some([nonempty]). Auto-detect resolved a non-emptyavailable_in_appagainstsupportedto an empty intersection: no stored credential on the active app satisfies the endpoint. - Wrong-app:
requested = None,available_in_app = Some([]),other_apps_with_creds = Some([nonempty]). The active app holds no credentials but other apps in the store do — the user likely forgot--app NAME.
app carries the active app name (when known) so the recovery hint
can substitute it. rendered_url carries the substituted path
(/2/users/12345/likes) for user-facing messages while endpoint
stays as the spec template (/2/users/{id}/likes) for agents to
pattern-match against.
The Display impl renders the same body that fills the envelope’s
message field.
Fields
endpoint: StringPath template (e.g. /2/users/{id}/likes) — keyed verbatim
against the spec for agent pattern matching.
rendered_url: Option<String>Path with {param} segments substituted from path_params
(e.g. /2/users/12345/likes). User-facing messages prefer this
over endpoint so the recovery hint doesn’t contain literal
brace placeholders. None when no substitution context was
available (e.g. construction outside a real call).
requested: Option<String>What the user asked for. Some("app"|"oauth1"|"oauth2") in the
explicit-mismatch shape; None in the empty-intersection and
wrong-app shapes.
available_in_app: Option<Vec<String>>Auth methods the active app actually has stored. None in the
explicit-mismatch shape; Some([nonempty]) in the empty-
intersection shape; Some([]) in the wrong-app shape.
Implementations§
Source§impl XurlError
impl XurlError
Sourcepub fn api(status: u16, body: impl Into<String>) -> Self
pub fn api(status: u16, body: impl Into<String>) -> Self
Create an API error with an HTTP status code and response body.
Sourcepub fn validation(body: impl Into<String>) -> Self
pub fn validation(body: impl Into<String>) -> Self
Create a validation error for non-HTTP error conditions.
Sourcepub fn auth(message: impl Into<String>) -> Self
pub fn auth(message: impl Into<String>) -> Self
Create an auth error with a descriptive message.
Sourcepub fn auth_with_cause(message: &str, cause: &dyn Display) -> Self
pub fn auth_with_cause(message: &str, cause: &dyn Display) -> Self
Create an auth error with a message and underlying cause.
Sourcepub fn token_store(message: impl Into<String>) -> Self
pub fn token_store(message: impl Into<String>) -> Self
Create a token store error.
Sourcepub fn is_validation(&self) -> bool
pub fn is_validation(&self) -> bool
Returns true if this is a validation error.
Sourcepub fn kind(&self) -> &'static str
pub fn kind(&self) -> &'static str
Returns a typed kebab-case identifier for this error.
The closed set is the envelope reason vocabulary that agents
pattern-match on. Never returns English; never embeds state.
| Variant | kind() |
|---|---|
Auth | auth-required |
TokenStore | token-store |
Api { 401, .. } | auth-required |
Api { 429, .. } | rate-limited |
Api { 404, .. } | not-found |
Api { other, .. } | network-error |
Http | network-error |
Io | io |
Json | serialization |
InvalidMethod | invalid-method |
Validation | validation |
InvalidUrl | invalid-url |
InvalidPathParam | invalid-path-param |
Internal | internal |
EnvelopeAlreadyEmitted | confirmation-required |
AuthMethodMismatch | auth-method-mismatch |
Trait Implementations§
Source§impl Error for XurlError
impl Error for XurlError
1.30.0 · 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()
Source§impl From<ParseError> for XurlError
impl From<ParseError> for XurlError
Source§fn from(err: ParseError) -> Self
fn from(err: ParseError) -> Self
Auto Trait Implementations§
impl Freeze for XurlError
impl RefUnwindSafe for XurlError
impl Send for XurlError
impl Sync for XurlError
impl Unpin for XurlError
impl UnsafeUnpin for XurlError
impl UnwindSafe for XurlError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.