Skip to main content

better_url/errors/
url.rs

1//! [`InvalidUrl`] and [`InvalidJoin`].
2
3use thiserror::Error;
4
5use crate::prelude::*;
6
7/// The enum of errors that can occur when trying to parse an invalid URL.
8#[derive(Debug, Error)]
9pub enum InvalidUrl {
10    /** [`InvalidScheme`].             */ #[error(transparent)] InvalidScheme            (#[from] InvalidScheme            ),
11    /** [`InvalidFileHost`].           */ #[error(transparent)] InvalidFileHost          (#[from] InvalidFileHost          ),
12    /** [`InvalidSpecialNotFileHost`]. */ #[error(transparent)] InvalidSpecialNotFileHost(#[from] InvalidSpecialNotFileHost),
13    /** [`InvalidNonSpecialHost`].     */ #[error(transparent)] InvalidNonSpecialHost    (#[from] InvalidNonSpecialHost    ),
14    /** [`InvalidPort`].               */ #[error(transparent)] InvalidPort              (#[from] InvalidPort              ),
15    /** [`TooLong`].                   */ #[error(transparent)] TooLong                  (#[from] TooLong                  ),
16
17    /// Returned when attempting to parse a URL with no scheme.
18    #[error("Attempted to parse a URL with no scheme.")]
19    MissingScheme,
20    /// Returned when attempting to parse a URL with an empty host and a userinfo and/or port.
21    #[error("Attempted to parse a URL with an empty host and a userinfo and/or port.")]
22    EmptyHostCantHaveUserinfoOrPort,
23}
24
25/// [`BetterUrl::join`].
26#[derive(Debug, Error)]
27pub enum InvalidJoin {
28    /** [`TooLong`].          */ #[error(transparent)] TooLong         (#[from] TooLong          ),
29    /** [`InvalidUrl`].       */ #[error(transparent)] InvalidUrl      (#[from] InvalidUrl       ),
30    /** [`InvalidScheme`].    */ #[error(transparent)] InvalidScheme   (#[from] InvalidScheme    ),
31    /** [`CannotBeABase`].    */ #[error(transparent)] CannotBeABase   (#[from] CannotBeABase    ),
32    /// Returned when attempting to join a non-relative URL with something other than just a fragment or a whole URL.
33    #[error("Attempted to join a non-relative URL with something other than a fragment or a whole URL.")]
34    MissingSchemeNonRelativeUrl,
35}
36
37/// Returned when attempting to join more than the fragment on a cannot-be-a-base URL.
38#[derive(Debug, Error)]
39#[error("Attempted to join more than the fragment on a cannot-be-a-base URL.")]
40pub struct CannotBeABase;