Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1333,3 +1333,13 @@ snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v
#### Added

- Initial release

### Cast

#### Added

- ClassAlreadyDeclared(Felt252) to the custom errors in `sncast/error.rs`.

#### Changed

- Match arm to include the new error message instead of the RPC provider error, for a more descriptive error.
7 changes: 5 additions & 2 deletions crates/sncast/src/response/errors.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::{ErrorData, WaitForTransactionError, handle_rpc_error};
use crate::{handle_rpc_error, ErrorData, WaitForTransactionError};
use anyhow::anyhow;
use cairo_vm::Felt252;
use console::style;
use conversions::serde::serialize::CairoSerialize;

use conversions::byte_array::ByteArray;

use foundry_ui::Message;
use serde::Serialize;
use serde_json::{Value, json};
use serde_json::{json, Value};
use starknet::core::types::{ContractErrorData, StarknetError, TransactionExecutionErrorData};
use starknet::providers::ProviderError;
use thiserror::Error;
Expand Down Expand Up @@ -51,6 +52,8 @@ pub enum StarknetCommandError {
WaitForTransactionError(#[from] WaitForTransactionError),
#[error(transparent)]
ProviderError(#[from] SNCastProviderError),
#[error("Contract with class hash {0} is already declared on Starknet.")]
ClassAlreadyDeclared(Felt252),
}

#[must_use]
Expand Down
10 changes: 6 additions & 4 deletions crates/sncast/src/starknet_commands/declare.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{Context, Result, anyhow};
use anyhow::{anyhow, Context, Result};
use clap::Args;
use conversions::IntoConv;
use conversions::byte_array::ByteArray;
use conversions::IntoConv;
use foundry_ui::UI;
use scarb_api::StarknetContractArtifacts;
use sncast::helpers::fee::{FeeArgs, FeeSettings};
Expand All @@ -10,7 +10,7 @@ use sncast::response::declare::{
AlreadyDeclaredResponse, DeclareResponse, DeclareTransactionResponse,
};
use sncast::response::errors::StarknetCommandError;
use sncast::{ErrorData, WaitForTx, apply_optional_fields, handle_wait_for_tx};
use sncast::{apply_optional_fields, handle_wait_for_tx, ErrorData, WaitForTx};
use starknet::accounts::AccountError::Provider;
use starknet::accounts::{ConnectedAccount, DeclarationV3};
use starknet::core::types::{DeclareTransactionResult, StarknetError};
Expand Down Expand Up @@ -135,7 +135,9 @@ pub async fn declare(
class_hash: class_hash.into_(),
}))
}
Err(Provider(error)) => Err(StarknetCommandError::ProviderError(error.into())),
Err(Provider(ProviderError::StarknetError(StarknetError::ClassAlreadyDeclared))) => Err(
StarknetCommandError::ClassAlreadyDeclared(class_hash.into_()),
),
Err(error) => Err(anyhow!(format!("Unexpected error occurred: {error}")).into()),
}
}
Loading