Skip to main content

pop_contracts/
errors.rs

1// SPDX-License-Identifier: GPL-3.0
2
3use pop_common::sourcing::Error as SourcingError;
4use thiserror::Error;
5
6/// Represents the various errors that can occur in the crate.
7#[derive(Error, Debug)]
8#[allow(clippy::enum_variant_names)]
9pub enum Error {
10	/// An error occurred.
11	#[error("Anyhow error: {0}")]
12	AnyhowError(#[from] anyhow::Error),
13	/// Failed to parse a balance value from a string representation.
14	#[error("Failed to parse balance: {0}")]
15	BalanceParsing(String),
16	/// Failed to call the smart contract.
17	#[error("{0}")]
18	CallContractError(String),
19	/// A contract metadata error happened
20	#[error("{0}")]
21	ContractMetadata(String),
22	/// A common error originating from `pop_common`.
23	#[error("{0}")]
24	CommonError(#[from] pop_common::Error),
25	/// Dry-run contract upload failed.
26	#[error("Pre-submission dry-run failed: {0}")]
27	DryRunUploadContractError(String),
28	/// Dry-run contract call failed.
29	#[error("Pre-submission dry-run failed: {0}")]
30	DryRunCallContractError(String),
31	/// Failed to parse hex-encoded bytes.
32	#[error("Failed to parse hex encoded bytes: {0}")]
33	HexParsing(String),
34	/// An HTTP request failed.
35	#[error("HTTP error: {0}")]
36	HttpError(#[from] reqwest::Error),
37	/// The number of provided arguments did not match the expected count.
38	#[error("Incorrect number of arguments provided. Expecting {expected}, {provided} provided")]
39	IncorrectArguments {
40		/// Number of arguments expected.
41		expected: usize,
42		/// Number of arguments provided.
43		provided: usize,
44	},
45	/// Failed to install the contracts node binary.
46	#[error("Failed to install {0}")]
47	InstallContractsNode(String),
48	/// Contract instantiation failed.
49	#[error("{0}")]
50	InstantiateContractError(String),
51	/// The specified constructor name is invalid.
52	#[error("Invalid constructor name: {0}")]
53	InvalidConstructorName(String),
54	/// The specified message name is invalid.
55	#[error("Invalid message name: {0}")]
56	InvalidMessageName(String),
57	/// The specified name is invalid.
58	#[error("Invalid name: {0}")]
59	InvalidName(String),
60	/// The current toolchain is invalid
61	#[error("Invalid toolchain: {0}")]
62	InvalidToolchain(String),
63	/// An I/O error occurred.
64	#[error("IO error: {0}")]
65	IO(#[from] std::io::Error),
66	/// An I/O error occurred.
67	#[error("Failed to get manifest path: {0}")]
68	ManifestPath(String),
69	/// Error returned when mapping an account fails.
70	#[error("Failed to map account: {0}")]
71	MapAccountError(String),
72	/// A required argument was not provided.
73	#[error("Argument {0} is required")]
74	MissingArgument(String),
75	/// An error occurred while creating a new contract project.
76	#[error("Failed to create new contract project: {0}")]
77	NewContract(String),
78	/// An error occurred while parsing a URL.
79	#[error("ParseError error: {0}")]
80	ParseError(#[from] url::ParseError),
81	/// The `Repository` property is missing from the template variant.
82	#[error("The `Repository` property is missing from the template variant")]
83	RepositoryMissing,
84	/// A `[serde_json::Error]` error occurred
85	#[error("Serde JSON error: {0}")]
86	SerdeJson(#[from] serde_json::Error),
87	/// An error occurred sourcing a binary.
88	#[error("Sourcing error {0}")]
89	SourcingError(SourcingError),
90	/// An error occurred while executing a test command.
91	#[error("Failed to execute test command: {0}")]
92	TestCommand(String),
93	/// The platform is unsupported.
94	#[error("Unsupported platform: {os}")]
95	UnsupportedPlatform {
96		/// The operating system in use.
97		os: &'static str,
98	},
99	/// An error occurred while uploading the contract.
100	#[error("{0}")]
101	UploadContractError(String),
102	/// An error occurred while verifying a contract
103	#[error("{0}")]
104	Verification(String),
105}