sn_testnet_deploy/
error.rs

1// Copyright (c) 2023, MaidSafe.
2// All rights reserved.
3//
4// This SAFE Network Software is licensed under the BSD-3-Clause license.
5// Please see the LICENSE file for more details.
6
7use std::net::IpAddr;
8
9use crate::{ansible::inventory::AnsibleInventoryType, NodeType};
10use evmlib::contract::network_token;
11use thiserror::Error;
12use tokio::task::JoinError;
13
14pub type Result<T, E = Error> = std::result::Result<T, E>;
15/// Internal error.
16#[derive(Debug, Error)]
17#[allow(missing_docs)]
18pub enum Error {
19    #[error(transparent)]
20    AddrParseError(#[from] std::net::AddrParseError),
21    #[error("Could not determine content length for asset")]
22    AssetContentLengthUndetermined,
23    #[error(transparent)]
24    AwsS3Error(#[from] Box<aws_sdk_s3::Error>),
25    #[error("The {0} environment variable must be set to use your cloud provider")]
26    CloudProviderCredentialsNotSupplied(String),
27    #[error("The {0} cloud provider is not supported yet")]
28    CloudProviderNotSupported(String),
29    #[error("The home data directory could not be retrieved")]
30    CouldNotRetrieveDataDirectory,
31    #[error("Failed to delete '{0}' from '{1}")]
32    DeleteS3ObjectError(String, String),
33    #[error("Authorization failed for the Digital Ocean API")]
34    DigitalOceanUnauthorized,
35    #[error("Unexpected response: {0} -- {1}")]
36    DigitalOceanUnexpectedResponse(u16, String),
37    #[error("The public IP address was not obtainable from the API response")]
38    DigitalOceanPublicIpAddressNotFound,
39    #[error("The provided ansible inventory is empty or does not exists {0}")]
40    EmptyInventory(AnsibleInventoryType),
41    #[error("Could not retrieve environment details for '{0}'")]
42    EnvironmentDetailsNotFound(String),
43    #[error("The '{0}' environment does not exist")]
44    EnvironmentDoesNotExist(String),
45    #[error("The environment name is required")]
46    EnvironmentNameRequired,
47    #[error("Could not convert '{0}' to an EnvironmentType variant")]
48    EnvironmentNameFromStringError(String),
49    #[error("No EVM node found in the inventory")]
50    EvmNodeNotFound,
51    #[error("EVM testnet data not found or could not be read")]
52    EvmTestnetDataNotFound,
53    #[error("Error parsing EVM testnet data: {0}")]
54    EvmTestnetDataParsingError(String),
55    #[error("Command that executed with {binary} failed. See output for details.")]
56    ExternalCommandRunFailed {
57        binary: String,
58        exit_status: std::process::ExitStatus,
59    },
60    #[error("Failed to parse key")]
61    FailedToParseKey,
62    #[error("Failed to retrieve filename")]
63    FilenameNotRetrieved,
64    #[error(transparent)]
65    FsExtraError(#[from] fs_extra::error::Error),
66    #[error("Could not obtain Genesis multiaddr")]
67    GenesisListenAddress,
68    #[error("To provision the remaining nodes the multiaddr of the genesis node must be supplied")]
69    GenesisMultiAddrNotSupplied,
70    #[error("Failed to retrieve '{0}' from '{1}")]
71    GetS3ObjectError(String, String),
72    #[error(transparent)]
73    InquireError(#[from] inquire::InquireError),
74    #[error("'{0}' is not a valid binary to build")]
75    InvalidBinaryName(String),
76    #[error("The node type '{0:?}' is not supported")]
77    InvalidNodeType(NodeType),
78    #[error("The number of wallet secret keys ({0}) does not match the number of uploaders ({1})")]
79    InvalidWalletCount(usize, usize),
80    #[error(
81        "The '{0}' deployment type for the environment is not supported for upscaling uploaders"
82    )]
83    InvalidUploaderUpscaleDeploymentType(String),
84    #[error("The desired auditor VM count is smaller than the current count. This is invalid for an upscale operation.")]
85    InvalidUpscaleDesiredAuditorVmCount,
86    #[error("The desired Peer Cache VM count is smaller than the current count. This is invalid for an upscale operation.")]
87    InvalidUpscaleDesiredPeerCacheVmCount,
88    #[error("The desired Peer Cache node count is smaller than the current count. This is invalid for an upscale operation.")]
89    InvalidUpscaleDesiredPeerCacheNodeCount,
90    #[error("The desired node VM count is smaller than the current count. This is invalid for an upscale operation.")]
91    InvalidUpscaleDesiredNodeVmCount,
92    #[error("The desired node count is smaller than the current count. This is invalid for an upscale operation.")]
93    InvalidUpscaleDesiredNodeCount,
94    #[error("The desired full cone private node VM count is smaller than the current count. This is invalid for an upscale operation.")]
95    InvalidUpscaleDesiredFullConePrivateNodeVmCount,
96    #[error("The desired symmetric private node VM count is smaller than the current count. This is invalid for an upscale operation.")]
97    InvalidUpscaleDesiredSymmetricPrivateNodeVmCount,
98    #[error("The desired full cone private node count is smaller than the current count. This is invalid for an upscale operation.")]
99    InvalidUpscaleDesiredFullConePrivateNodeCount,
100    #[error("The desired symmetric private node count is smaller than the current count. This is invalid for an upscale operation.")]
101    InvalidUpscaleDesiredSymmetricPrivateNodeCount,
102    #[error("The desired uploader count is smaller than the current count. This is invalid for an upscale operation.")]
103    InvalidUpscaleDesiredUploaderCount,
104    #[error("The desired uploader VM count is smaller than the current count. This is invalid for an upscale operation.")]
105    InvalidUpscaleDesiredUploaderVmCount,
106    #[error("Options were used that are not applicable to a bootstrap deployment")]
107    InvalidUpscaleOptionsForBootstrapDeployment,
108    #[error("The vm count for the provided custom vms are not equal: {0:?} != {1:?}")]
109    VmCountMismatch(Option<AnsibleInventoryType>, Option<AnsibleInventoryType>),
110    #[error(transparent)]
111    Io(#[from] std::io::Error),
112    #[error("Could not obtain IpDetails")]
113    IpDetailsNotObtained,
114    #[error(transparent)]
115    JoinError(#[from] JoinError),
116    #[error("Failed to list objects in S3 bucket with prefix '{prefix}': {error}")]
117    ListS3ObjectsError { prefix: String, error: String },
118    #[error("Could not configure logging: {0}")]
119    LoggingConfiguration(String),
120    #[error("Logs for a '{0}' testnet already exist")]
121    LogsForPreviousTestnetExist(String),
122    #[error("Logs have not been retrieved for the '{0}' environment.")]
123    LogsNotRetrievedError(String),
124    #[error("The API response did not contain the expected '{0}' value")]
125    MalformedDigitalOceanApiRespose(String),
126    #[error("Could not convert from DeployOptions to ProvisionOptions: peer cache node count must have a value")]
127    MissingPeerCacheNodeCount,
128    #[error(
129        "Could not convert from DeployOptions to ProvisionOptions: node count must have a value"
130    )]
131    MissingNodeCount,
132    #[error("The NAT gateway VM was not supplied")]
133    NatGatewayNotSupplied,
134    #[error(transparent)]
135    NetworkTokenError(#[from] network_token::Error),
136    #[error("This deployment does not have an auditor. It may be a bootstrap deployment.")]
137    NoAuditorError,
138    #[error("This deployment does not have a faucet. It may be a bootstrap deployment.")]
139    NoFaucetError,
140    #[error("This deployment does not have any uploaders. It may be a bootstrap deployment.")]
141    NoUploadersError,
142    #[error("The node count for the provided custom vms are not equal")]
143    NodeCountMismatch,
144    #[error("Could not obtain a multiaddr from the node inventory")]
145    NodeAddressNotFound,
146    #[error("Failed to upload {0} to S3 bucket {1}")]
147    PutS3ObjectError(String, String),
148    #[error(transparent)]
149    RegexError(#[from] regex::Error),
150    #[error(transparent)]
151    ReqwestError(#[from] reqwest::Error),
152    #[error("The rewards address must be supplied")]
153    RewardsAddressNotSet,
154    #[error("Routed VM for IP {0} not found")]
155    RoutedVmNotFound(IpAddr),
156    #[error("Safe client command failed: {0}")]
157    SafeCmdError(String),
158    #[error("Failed to download the safe or safenode binary")]
159    SafeBinaryDownloadError,
160    #[error("Error in byte stream when attempting to retrieve S3 object")]
161    S3ByteStreamError,
162    #[error("The secret key was not found in the environment")]
163    SecretKeyNotFound,
164    #[error(transparent)]
165    SerdeJson(#[from] serde_json::Error),
166    #[error("An unexpected error occurred during the setup process")]
167    SetupError,
168    #[error("The SLACK_WEBHOOK_URL variable was not set")]
169    SlackWebhookUrlNotSupplied,
170    #[error("SSH command failed: {0}")]
171    SshCommandFailed(String),
172    #[error("Failed to obtain lock to update SSH settings")]
173    SshSettingsRwLockError,
174    #[error("After several retry attempts an SSH connection could not be established")]
175    SshUnavailable,
176    #[error(transparent)]
177    StripPrefixError(#[from] std::path::StripPrefixError),
178    #[error(transparent)]
179    TemplateError(#[from] indicatif::style::TemplateError),
180    #[error("Terraform show failed")]
181    TerraformShowFailed,
182    #[error("Terraform resource not found {0}")]
183    TerraformResourceNotFound(String),
184    #[error("Missing terraform resource field {0}")]
185    TerraformResourceFieldMissing(String),
186    #[error("Mismatch of a terraform resource value {expected} != {actual}")]
187    TerraformResourceValueMismatch { expected: String, actual: String },
188    #[error("The '{0}' binary was not found. It is required for the deploy process. Make sure it is installed.")]
189    ToolBinaryNotFound(String),
190    #[error("The {0} type is not yet supported for an upscaling provision")]
191    UpscaleInventoryTypeNotSupported(String),
192    #[error(transparent)]
193    VarError(#[from] std::env::VarError),
194}