1use 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#[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("The node type '{0:?}' is not supported")]
75 InvalidNodeType(NodeType),
76 #[error(
77 "The '{0}' deployment type for the environment is not supported for upscaling uploaders"
78 )]
79 InvalidUploaderUpscaleDeploymentType(String),
80 #[error("The desired auditor VM count is smaller than the current count. This is invalid for an upscale operation.")]
81 InvalidUpscaleDesiredAuditorVmCount,
82 #[error("The desired Peer Cache VM count is smaller than the current count. This is invalid for an upscale operation.")]
83 InvalidUpscaleDesiredPeerCacheVmCount,
84 #[error("The desired Peer Cache node count is smaller than the current count. This is invalid for an upscale operation.")]
85 InvalidUpscaleDesiredPeerCacheNodeCount,
86 #[error("The desired node VM count is smaller than the current count. This is invalid for an upscale operation.")]
87 InvalidUpscaleDesiredNodeVmCount,
88 #[error("The desired node count is smaller than the current count. This is invalid for an upscale operation.")]
89 InvalidUpscaleDesiredNodeCount,
90 #[error("The desired full cone private node VM count is smaller than the current count. This is invalid for an upscale operation.")]
91 InvalidUpscaleDesiredFullConePrivateNodeVmCount,
92 #[error("The desired symmetric private node VM count is smaller than the current count. This is invalid for an upscale operation.")]
93 InvalidUpscaleDesiredSymmetricPrivateNodeVmCount,
94 #[error("The desired full cone private node count is smaller than the current count. This is invalid for an upscale operation.")]
95 InvalidUpscaleDesiredFullConePrivateNodeCount,
96 #[error("The desired symmetric private node count is smaller than the current count. This is invalid for an upscale operation.")]
97 InvalidUpscaleDesiredSymmetricPrivateNodeCount,
98 #[error("The desired uploader count is smaller than the current count. This is invalid for an upscale operation.")]
99 InvalidUpscaleDesiredUploaderCount,
100 #[error("The desired uploader VM count is smaller than the current count. This is invalid for an upscale operation.")]
101 InvalidUpscaleDesiredUploaderVmCount,
102 #[error("Options were used that are not applicable to a bootstrap deployment")]
103 InvalidUpscaleOptionsForBootstrapDeployment,
104 #[error("The vm count for the provided custom vms are not equal: {0:?} != {1:?}")]
105 VmCountMismatch(Option<AnsibleInventoryType>, Option<AnsibleInventoryType>),
106 #[error(transparent)]
107 Io(#[from] std::io::Error),
108 #[error("Could not obtain IpDetails")]
109 IpDetailsNotObtained,
110 #[error(transparent)]
111 JoinError(#[from] JoinError),
112 #[error("Failed to list objects in S3 bucket with prefix '{prefix}': {error}")]
113 ListS3ObjectsError { prefix: String, error: String },
114 #[error("Could not configure logging: {0}")]
115 LoggingConfiguration(String),
116 #[error("Logs for a '{0}' testnet already exist")]
117 LogsForPreviousTestnetExist(String),
118 #[error("Logs have not been retrieved for the '{0}' environment.")]
119 LogsNotRetrievedError(String),
120 #[error("The API response did not contain the expected '{0}' value")]
121 MalformedDigitalOceanApiRespose(String),
122 #[error("Could not convert from DeployOptions to ProvisionOptions: peer cache node count must have a value")]
123 MissingPeerCacheNodeCount,
124 #[error(
125 "Could not convert from DeployOptions to ProvisionOptions: node count must have a value"
126 )]
127 MissingNodeCount,
128 #[error("The NAT gateway VM was not supplied")]
129 NatGatewayNotSupplied,
130 #[error(transparent)]
131 NetworkTokenError(#[from] network_token::Error),
132 #[error("This deployment does not have an auditor. It may be a bootstrap deployment.")]
133 NoAuditorError,
134 #[error("This deployment does not have a faucet. It may be a bootstrap deployment.")]
135 NoFaucetError,
136 #[error("This deployment does not have any uploaders. It may be a bootstrap deployment.")]
137 NoUploadersError,
138 #[error("The node count for the provided custom vms are not equal")]
139 NodeCountMismatch,
140 #[error("Could not obtain a multiaddr from the node inventory")]
141 NodeAddressNotFound,
142 #[error("Failed to upload {0} to S3 bucket {1}")]
143 PutS3ObjectError(String, String),
144 #[error(transparent)]
145 RegexError(#[from] regex::Error),
146 #[error(transparent)]
147 ReqwestError(#[from] reqwest::Error),
148 #[error("Routed VM for IP {0} not found")]
149 RoutedVmNotFound(IpAddr),
150 #[error("Safe client command failed: {0}")]
151 SafeCmdError(String),
152 #[error("Failed to download the safe or safenode binary")]
153 SafeBinaryDownloadError,
154 #[error("Error in byte stream when attempting to retrieve S3 object")]
155 S3ByteStreamError,
156 #[error("The secret key was not found in the environment")]
157 SecretKeyNotFound,
158 #[error(transparent)]
159 SerdeJson(#[from] serde_json::Error),
160 #[error("An unexpected error occurred during the setup process")]
161 SetupError,
162 #[error("The SLACK_WEBHOOK_URL variable was not set")]
163 SlackWebhookUrlNotSupplied,
164 #[error("SSH command failed: {0}")]
165 SshCommandFailed(String),
166 #[error("Failed to obtain lock to update SSH settings")]
167 SshSettingsRwLockError,
168 #[error("After several retry attempts an SSH connection could not be established")]
169 SshUnavailable,
170 #[error(transparent)]
171 StripPrefixError(#[from] std::path::StripPrefixError),
172 #[error(transparent)]
173 TemplateError(#[from] indicatif::style::TemplateError),
174 #[error("Terraform show failed")]
175 TerraformShowFailed,
176 #[error("Terraform resource not found {0}")]
177 TerraformResourceNotFound(String),
178 #[error("Missing terraform resource field {0}")]
179 TerraformResourceFieldMissing(String),
180 #[error("Mismatch of a terraform resource value {expected} != {actual}")]
181 TerraformResourceValueMismatch { expected: String, actual: String },
182 #[error("The '{0}' binary was not found. It is required for the deploy process. Make sure it is installed.")]
183 ToolBinaryNotFound(String),
184 #[error("The {0} type is not yet supported for an upscaling provision")]
185 UpscaleInventoryTypeNotSupported(String),
186 #[error(transparent)]
187 VarError(#[from] std::env::VarError),
188}