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
mod assets;
mod upload;

pub use assets::{init_kv, AssetIndex, AssetMetadata, KVAssets, KV};

// for non-wasm, export asset builders that depend on std::fs and wrangler libs
#[cfg(not(target_arch = "wasm32"))]
pub use upload::{sync_assets, SyncConfig};

use thiserror::Error as ThisError;
#[derive(Clone, Debug, ThisError)]
pub enum Error {
    #[error("KV Api error {0} (body) {1}")]
    #[allow(clippy::upper_case_acronyms)]
    KVHttp(String, String),

    #[error("KV Api error Status {0} (body) {1}")]
    #[allow(clippy::upper_case_acronyms)]
    KVHttpStatus(u16, String),

    #[error("KV Key {0} not found. status={1}")]
    #[allow(clippy::upper_case_acronyms)]
    KVKeyNotFound(String, u16),

    #[error("Deserializing assets:{0}")]
    DeserializeAssets(String),

    #[error("Empty key passed to lookup")]
    EmptyKey,

    #[cfg(not(target_arch = "wasm32"))]
    #[error("Wangler error: {0}")]
    Wrangler(String),

    #[cfg(not(target_arch = "wasm32"))]
    #[error("IO Error: {0}")]
    #[allow(clippy::upper_case_acronyms)]
    IO(String),

    #[cfg(not(target_arch = "wasm32"))]
    #[error("Invalid asset output path: {0}")]
    InvalidAssetsBinPath(String),

    #[cfg(not(target_arch = "wasm32"))]
    #[error("creating output directory {0}")]
    CreateDir(String),

    #[cfg(not(target_arch = "wasm32"))]
    #[error("Invalid asset path: not a directory: {0}")]
    InvalidAssetPath(String),

    #[cfg(not(target_arch = "wasm32"))]
    #[error("Missing config file {0}")]
    MissingWranglerFile(String),

    #[error("TTL to short. Must be at least 60 seconds")]
    #[allow(clippy::upper_case_acronyms)]
    TTLTooShort,

    // catch-all
    #[error("{0}")]
    Message(String),
}

#[cfg(not(target_arch = "wasm32"))]
impl From<failure::Error> for Error {
    fn from(e: failure::Error) -> Error {
        Error::Wrangler(format!("{:?}", e))
    }
}