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
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use thiserror::Error;

#[derive(Error, Debug, PartialEq, Eq)]
pub enum FaucetError {
    #[error("Faucet cannot read objects from fullnode: {0}")]
    FullnodeReadingError(String),

    #[error("Failed to parse transaction response {0}")]
    ParseTransactionResponseError(String),

    #[error(
        "Gas coin `{0}` does not have sufficient balance and has been removed from gas coin pool"
    )]
    GasCoinWithInsufficientBalance(String),

    #[error("Faucet does not have enough balance")]
    InsuffientBalance,

    #[error("Gas coin `{0}` is not valid and has been removed from gas coin pool")]
    InvalidGasCoin(String),

    #[error("Timed out waiting for a coin from the gas coin pool")]
    NoGasCoinAvailable,

    #[error("Wallet Error: `{0}`")]
    Wallet(String),

    #[error("Coin Transfer Failed `{0}`")]
    Transfer(String),

    #[error("Too many coins in the batch queue. Please try again later.")]
    BatchSendQueueFull,

    #[error("Request consumer queue closed.")]
    ChannelClosed,

    #[error("Coin amounts sent are incorrect:`{0}`")]
    CoinAmountTransferredIncorrect(String),

    #[error("Internal error: {0}")]
    Internal(String),
}

impl FaucetError {
    pub(crate) fn internal(e: impl ToString) -> Self {
        FaucetError::Internal(e.to_string())
    }
}