Skip to content

Commit

Permalink
use thiserror
Browse files Browse the repository at this point in the history
  • Loading branch information
brunopgalvao committed Apr 18, 2024
1 parent bd34ff4 commit 6f5469b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions crates/pop-contracts/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ use thiserror::Error;
pub enum Error {
#[error("Failed to create new contract project: {0}")]
NewContractFailed(String),

#[error("IO error: {0}")]
IO(#[from] std::io::Error),

#[error("Failed to execute test command: {0}")]
TestCommand(String),

#[error("Failed to parse balance: {0}")]
BalanceParsing(String),

#[error("Failed to parse account address: {0}")]
AccountAddressParsing(String),

#[error("Failed to get manifest path: {0}")]
ManifestPath(String),
}
2 changes: 1 addition & 1 deletion crates/pop-parachains/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum Error {
PalletDirCreation,

#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
IO(#[from] std::io::Error),

#[error("Git error: {0}")]
GitError(String),
Expand Down
7 changes: 4 additions & 3 deletions crates/pop-parachains/src/new_pallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
resolve_pallet_path,
utils::helpers::sanitize,
};
use crate::errors::Error;

pub struct TemplatePalletConfig {
pub name: String,
Expand All @@ -17,7 +18,7 @@ pub struct TemplatePalletConfig {
pub fn create_pallet_template(
path: Option<String>,
config: TemplatePalletConfig,
) -> anyhow::Result<()> {
) -> Result<(), Error> {
let target = resolve_pallet_path(path)?;
let pallet_name = config.name.clone();
let pallet_path = target.join(pallet_name.clone());
Expand All @@ -29,7 +30,7 @@ pub fn create_pallet_template(
}

/// Generate a pallet folder and file structure
fn generate_pallet_structure(target: &PathBuf, pallet_name: &str) -> anyhow::Result<()> {
fn generate_pallet_structure(target: &PathBuf, pallet_name: &str) -> Result<(), Error> {
use fs::{create_dir, File};
let (pallet, src) = (target.join(pallet_name), target.join(pallet_name.to_string() + "/src"));
create_dir(&pallet)?;
Expand All @@ -46,7 +47,7 @@ fn render_pallet(
pallet_name: String,
config: TemplatePalletConfig,
pallet_path: &PathBuf,
) -> anyhow::Result<()> {
) -> Result<(), Error> {
let pallet_name = pallet_name.replace('-', "_");
// Todo `module` must be of the form Template if pallet_name : `pallet_template`
let pallet: Vec<Box<dyn PalletItem>> = vec![
Expand Down
4 changes: 2 additions & 2 deletions crates/pop-parachains/src/up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Zombienet {
// Parse network config
let network_config_path = PathBuf::from(network_config);
let config = std::fs::read_to_string(&network_config_path)
.map_err(|err| Error::IoError(err))
.map_err(|err| Error::IO(err))
.and_then(|content| {
content.parse::<DocumentMut>().map_err(|err| Error::TomlError(err.into()))
})?;
Expand Down Expand Up @@ -236,7 +236,7 @@ impl Zombienet {
let network_config_file = Builder::new()
.suffix(".toml")
.tempfile()
.map_err(|err| Error::IoError(err))
.map_err(|err| Error::IO(err))
.expect("network config could not be created with .toml extension");
let path = network_config_file
.path()
Expand Down

0 comments on commit 6f5469b

Please sign in to comment.