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