1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*!
Provides the `IRI` specific `Error` and `Result` types.

# Example

The following demonstrates the use of [`ErrorKind`](enum.ErrorKind.html) in constructing an error
to return to the caller.

```rust
use rdftk_iri::IRI;
use rdftk_iri::error::{ErrorKind, Result as IriResult};

fn some_operation() -> IriResult<IRI> {
    Err(ErrorKind::IsEmpty.into())
}
```

*/

// ------------------------------------------------------------------------------------------------
// Public Types
// ------------------------------------------------------------------------------------------------

///
/// Determines the component of the URI signaling the error. This is used by lower-level errors
/// such as character parsing.
///
#[derive(Debug)]
pub enum Component {
    /// The 'scheme' component of the IRI.
    Scheme,
    /// The 'authority' component of the IRI.
    Authority,
    /// The 'path' component of the IRI.
    Path,
    /// The 'query' component of the IRI.
    Query,
    /// The 'fragment' component of the IRI.
    Fragment,
}

error_chain! {
    errors {
        #[doc = "An IRI cannot be constructed from the empty string."]
        IsEmpty {
            description("An IRI cannot be constructed from the empty string.")
            display("An IRI cannot be constructed from the empty string.")
        }
        #[doc = "An error occurred parsing the IRI scheme."]
        ParseSchemeError(s: String) {
            description("An error occurred parsing the IRI scheme.")
            display("An error occurred parsing the IRI scheme: {:?}.", s)
        }
        #[doc = "An error occurred parsing the IRI authority."]
        ParseAuthorityError(s: String) {
            description("An error occurred parsing the IRI authority.")
            display("An error occurred parsing the IRI authority: {:?}.", s)
        }
        #[doc = "An error occurred parsing the IRI IP address name."]
        ParseIpAddressError(s: String) {
            description("An error occurred parsing the IRI IP address name.")
            display("An error occurred parsing the IRI IP address name: {:?}.", s)
        }
        #[doc = "An error occurred parsing the IRI host name."]
        ParseHostError(s: String) {
            description("An error occurred parsing the IRI host name.")
            display("An error occurred parsing the IRI host name: {:?}.", s)
        }
        #[doc = "An error occurred parsing the IRI port number."]
        ParsePortError(s: String) {
            description("An error occurred parsing the IRI port number.")
            display("An error occurred parsing the IRI port number: {:?}.", s)
        }
        #[doc = "An error occurred parsing the IRI user info."]
        ParseUserInfoError(s: String) {
            description("An error occurred parsing the IRI user info.")
            display("An error occurred parsing the IRI user info: {:?}.", s)
        }
        #[doc = "An error occurred parsing the IRI fragment."]
        ParseFragmentError(s: String) {
            description("An error occurred parsing the IRI fragment.")
            display("An error occurred parsing the IRI fragment: {:?}.", s)
        }
        #[doc = "An error occurred normalizing an IRI component."]
        Normalization(c: Component) {
            description("An error occurred normalizing an IRI component.")
            display("An error occurred normalizing the {:?} IRI component.", c)
        }
        #[doc = "An invalid character was found."]
        InvalidChar(c: Component) {
            description("An invalid character was found.")
            display("An invalid character was found in the {:?} IRI component.", c)
        }
        #[doc = "Provided String value is not a valid IRI."]
        Syntax(s: String) {
            description("Provided String value is not a valid IRI.")
            display("Provided String value `{}` was is a valid IRI.", s)
        }
        #[doc = "The current IRI is not a valid base URI (RFC-3986§5.2.1)."]
        NotValidBase {
            description("The current IRI is not a valid base URI (RFC-3986§5.2.1).")
            display("The current IRI is not a valid base URI (RFC-3986§5.2.1).")
        }
        #[doc = "A PrefixedName may not have an empty name part."]
        EmptyPrefixedName {
            description("A PrefixedName may not have an empty name part.")
            display("A PrefixedName may not have an empty name part.")
        }
        #[doc = "The String value provided is not a valid PrefixedName."]
        InvalidPrefixedName(s: String) {
            description("The String value provided is not a valid PrefixedName.")
            display("The String value `{}` is not a valid PrefixedName.", s)
        }
    }
}