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
//! Error produced by YouTube and this library

/// Errors produced by this Library
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// A Error that can occur when requesting web content
    #[error("An Error occurred while requesting web content: {0}")]
    Request(#[from] reqwest::Error),

    /// A Error reported by YouTube
    #[error(transparent)]
    Youtube(#[from] Youtube),
}

/// A Error reported by YouTube.
///
/// This Error is `#[non_exhaustive]` because YouTube can add errors at any
/// moment and breaking major version every time is annoying.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Youtube {
    /// A entity was not found. This can be:
    ///
    /// - [`Videos`](crate::Video)
    /// - [`Playlists`](crate::Playlist)
    /// - [`Channels`](crate::Channel)
    /// - [`Streams`](crate::Stream)
    #[error("a entity was not found")]
    NotFound,

    /// A entity is private. This can be:
    ///
    /// - [`Videos`](crate::Video)
    /// - [`Playlists`](crate::Playlist)
    /// - [`Channels`](crate::Channel)
    /// - [`Streams`](crate::Stream)
    #[error("a entity is private")]
    Private,

    /// A Video is not available due to Community Guideline violations.
    #[error("a video is not available due to community guideline violations")]
    CommunityGuidelineViolation,

    /// A Video is not available in your country.
    ///
    /// Maybe try tor :^)
    #[error("a video is not available in your country")]
    GeoRestricted,

    /// A [`Stream`](crate::Stream) is only available after a purchase.
    #[error("a purchase is required to watch get this stream")]
    PurchaseRequired,

    /// A [`Playlist`](crate::Playlist) could not be viewed. Reasons being:
    ///
    /// - The playlist is a "Mix" or "My Mix" playlist
    #[error("a playlist could not be viewed")]
    Unviewable,
}

/// The Error produced when a invalid Id is found
#[derive(thiserror::Error, Debug, Clone)]
pub enum Id<const N: usize> {
    /// A invalid Id was found.
    ///
    /// A Id is only valid when all characters are on of:
    ///
    /// - `0..=9`
    /// - `a..=z`
    /// - `A..=Z`
    /// - `_`
    /// - `-`
    #[error("Found invalid id: '{0}'")]
    InvalidId(String),

    /// A Id was not the expected length
    #[error("Expected a id of length {N} but found a id of length {0}")]
    InvalidLength(usize),
}