Skip to main content

http_url/
error.rs

1use alloc::string::String;
2use thiserror::Error;
3
4/// Convenience alias for crate results using [`HttpUrlError`].
5pub type Result<T> = core::result::Result<T, HttpUrlError>;
6
7/// Errors that can occur when parsing or building an HttpUrl.
8#[derive(Error, Debug, Clone, PartialEq, Eq)]
9pub enum HttpUrlError {
10    /// The URL string is empty.
11    #[error("URL is empty")]
12    EmptyUrl,
13
14    /// Missing scheme (e.g., "http", "https").
15    #[error("missing scheme (expected 'http' or 'https')")]
16    MissingScheme,
17
18    /// Unsupported scheme (only "http" and "https" are supported).
19    #[error("unsupported scheme: '{0}'")]
20    UnsupportedScheme(String),
21
22    /// Missing host after "://".
23    #[error("missing host")]
24    MissingHost,
25
26    /// Invalid port number.
27    #[error("invalid port: '{0}'")]
28    InvalidPort(String),
29
30    /// Port number out of range (must be 0–65535).
31    #[error("port out of range: {0}")]
32    PortOutOfRange(u64),
33
34    /// Invalid host (e.g., empty label, too long, bad characters).
35    #[error("invalid host: '{0}'")]
36    InvalidHost(String),
37
38    /// Invalid percent-encoding (e.g., "%ZZ" or "%XX" with non-hex chars).
39    #[error("invalid percent-encoding: '{0}'")]
40    InvalidPercentEncoding(String),
41
42    /// Unicode normalization failure.
43    #[error("unicode normalization error")]
44    UnicodeError,
45
46    /// Builder validation failed.
47    #[error("builder validation error: {0}")]
48    BuilderValidation(String),
49}