fidl_fuchsia_pkg_ext/
errors.rs

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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use thiserror::Error;

#[derive(Debug, Error, Clone)]
pub enum ResolveError {
    #[error("the resolver encountered an otherwise unspecified error while handling the request")]
    Internal,

    #[error("the resolver does not have permission to fetch a package blob")]
    AccessDenied,

    #[error("some unspecified error during I/O")]
    Io,

    #[error("the blob does not exist")]
    BlobNotFound,

    #[error("the package does not exist")]
    PackageNotFound,

    #[error("the resolver does not know about the repo")]
    RepoNotFound,

    #[error("there is no space available to store the package or metadata")]
    NoSpace,

    #[error("the resolver is currently unable to fetch a package blob")]
    UnavailableBlob,

    #[error("the resolver is currently unable to fetch a repository's metadata")]
    UnavailableRepoMetadata,

    #[error("the `package_url` provided to resolver is invalid")]
    InvalidUrl,

    #[error("the `context` provided to resolver is invalid")]
    InvalidContext,
}

impl From<fidl_fuchsia_pkg::ResolveError> for ResolveError {
    fn from(e: fidl_fuchsia_pkg::ResolveError) -> Self {
        use fidl_fuchsia_pkg::ResolveError as ferror;
        use ResolveError::*;
        match e {
            ferror::Internal => Internal,
            ferror::AccessDenied => AccessDenied,
            ferror::Io => Io,
            ferror::BlobNotFound => BlobNotFound,
            ferror::PackageNotFound => PackageNotFound,
            ferror::RepoNotFound => RepoNotFound,
            ferror::NoSpace => NoSpace,
            ferror::UnavailableBlob => UnavailableBlob,
            ferror::UnavailableRepoMetadata => UnavailableRepoMetadata,
            ferror::InvalidUrl => InvalidUrl,
            ferror::InvalidContext => InvalidContext,
        }
    }
}

impl From<ResolveError> for fidl_fuchsia_pkg::ResolveError {
    fn from(e: ResolveError) -> Self {
        use fidl_fuchsia_pkg::ResolveError as ferror;
        use ResolveError::*;
        match e {
            Internal => ferror::Internal,
            AccessDenied => ferror::AccessDenied,
            Io => ferror::Io,
            BlobNotFound => ferror::BlobNotFound,
            PackageNotFound => ferror::PackageNotFound,
            RepoNotFound => ferror::RepoNotFound,
            NoSpace => ferror::NoSpace,
            UnavailableBlob => ferror::UnavailableBlob,
            UnavailableRepoMetadata => ferror::UnavailableRepoMetadata,
            InvalidUrl => ferror::InvalidUrl,
            InvalidContext => ferror::InvalidContext,
        }
    }
}

#[derive(Error, Debug, PartialEq)]
pub enum BlobIdParseError {
    #[error("cannot contain uppercase hex characters")]
    CannotContainUppercase,

    #[error("invalid length, expected {} hex bytes, got {0}", crate::types::BLOB_ID_SIZE)]
    InvalidLength(usize),

    #[error("invalid hex")]
    FromHexError(#[from] hex::FromHexError),
}

#[derive(Error, Debug)]
pub enum BlobIdFromSliceError {
    #[error("invalid length, expected {} bytes, got {0}", crate::types::BLOB_ID_SIZE)]
    InvalidLength(usize),
}

#[derive(Error, Debug)]
pub enum ResolutionContextError {
    #[error("bytes was neither empty nor a valid BlobId")]
    InvalidBlobId(#[source] BlobIdFromSliceError),
}

#[derive(Error, Debug)]
pub enum MirrorConfigError {
    #[error("Mirror URLs must have schemes")]
    MirrorUrlMissingScheme,

    #[error("Blob mirror URLs must have schemes")]
    BlobMirrorUrlMissingScheme,
}

#[derive(Error, Debug)]
pub enum RepositoryParseError {
    #[error("unsupported key type")]
    UnsupportedKeyType,

    #[error("missing required field repo_url")]
    RepoUrlMissing,

    #[error("missing required field mirror_url")]
    MirrorUrlMissing,

    #[error("missing required field subscribe")]
    SubscribeMissing,

    #[error("invalid repository url")]
    InvalidRepoUrl(#[source] fuchsia_url::ParseError),

    #[error("invalid update package url")]
    InvalidUpdatePackageUrl(#[source] fuchsia_url::ParseError),

    #[error("invalid root version: {0}")]
    InvalidRootVersion(u32),

    #[error("invalid root threshold: {0}")]
    InvalidRootThreshold(u32),

    #[error("invalid uri")]
    InvalidUri(#[from] http::uri::InvalidUri),

    #[error("invalid config")]
    MirrorConfig(#[from] MirrorConfigError),
}

#[derive(Error, Debug)]
pub enum RepositoryUrlParseError {
    #[error("invalid repository url")]
    InvalidRepoUrl(#[source] fuchsia_url::ParseError),
}

#[derive(Debug, thiserror::Error)]
pub enum CupMissingField {
    #[error("CupData response field")]
    Response,
    #[error("CupData request field")]
    Request,
    #[error("CupData key_id field")]
    KeyId,
    #[error("CupData nonce field")]
    Nonce,
    #[error("CupData signature field")]
    Signature,
}