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
// Copyright 2020 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 {
    fuchsia_hash::ParseHashError,
    fuchsia_pkg::{PackagePathSegmentError, ParsePackagePathError},
    std::{io, str::Utf8Error},
    thiserror::Error,
};

#[derive(Debug, Error)]
pub enum PathHashMappingError {
    #[error("entry has no '=': '{entry:?}'")]
    EntryHasNoEqualsSign { entry: String },

    #[error("io error")]
    IoError(#[from] io::Error),

    #[error("invalid hash")]
    ParseHash(#[from] ParseHashError),

    #[error("invalid package path")]
    ParsePackagePath(#[from] ParsePackagePathError),
}

#[derive(Debug, Error)]
pub enum AllowListError {
    #[error("encoding error")]
    Encoding(#[from] Utf8Error),

    #[error("invalid package name")]
    PackageName(#[from] PackagePathSegmentError),
}

#[derive(Debug, Error)]
pub enum CachePackagesInitError {
    #[error("while reading data/cache_packages.json file")]
    ReadCachePackagesJson(#[source] package_directory::ReadFileError),

    #[error("while reading data/cache_packages file")]
    ReadCachePackages(#[source] package_directory::ReadFileError),

    #[error("while processing data/cache_packages")]
    ProcessingCachePackages(#[from] PathHashMappingError),

    #[error("while parsing data/cache_packages")]
    ParseConfig(#[from] fuchsia_url::errors::ParseError),

    #[error("json parsing error while reading packages config")]
    JsonError(#[source] serde_json::error::Error),

    #[error("packages config version not supported: '{0:?}'")]
    VersionNotSupported(String),

    #[error("non empty cache_packages.json should have at least 1 package")]
    NoCachePackages,
}

#[derive(Debug, Error)]
pub enum StaticPackagesInitError {
    #[error("while reading data/static_packages file")]
    ReadStaticPackages(#[source] package_directory::ReadFileError),

    #[error("while processing data/static_packages")]
    ProcessingStaticPackages(#[source] PathHashMappingError),
}