Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

v1.1 backport custom error rename #9826

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ impl CliConfig<'_> {
if !self.signers.is_empty() {
self.signers[0].try_pubkey()
} else {
Err(SignerError::CustomError(
Err(SignerError::Custom(
"Default keypair must be set if pubkey arg not provided".to_string(),
))
}
Expand Down Expand Up @@ -2282,7 +2282,7 @@ where
Err(err) => {
if let ClientErrorKind::TransactionError(TransactionError::InstructionError(
_,
InstructionError::CustomError(code),
InstructionError::Custom(code),
)) = err.kind()
{
if let Some(specific_error) = E::decode_custom_error_to_enum(*code) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1988,14 +1988,14 @@ mod tests {
meta.err,
Some(TransactionError::InstructionError(
0,
InstructionError::CustomError(1)
InstructionError::Custom(1)
))
);
assert_eq!(
meta.status,
Err(TransactionError::InstructionError(
0,
InstructionError::CustomError(1)
InstructionError::Custom(1)
))
);
} else {
Expand Down
4 changes: 2 additions & 2 deletions core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2649,14 +2649,14 @@ pub(crate) mod tests {
meta.err,
Some(TransactionError::InstructionError(
0,
InstructionError::CustomError(1)
InstructionError::Custom(1)
))
);
assert_eq!(
meta.status,
Err(TransactionError::InstructionError(
0,
InstructionError::CustomError(1)
InstructionError::Custom(1)
))
);
} else {
Expand Down
12 changes: 6 additions & 6 deletions core/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2076,7 +2076,7 @@ pub mod tests {
);
let res = io.handle_request_sync(&req, meta);
let expected_res: Option<transaction::Result<()>> = Some(Err(
TransactionError::InstructionError(0, InstructionError::CustomError(1)),
TransactionError::InstructionError(0, InstructionError::Custom(1)),
));
let expected = json!({
"jsonrpc": "2.0",
Expand Down Expand Up @@ -2137,7 +2137,7 @@ pub mod tests {
let res = io.handle_request_sync(&req, meta.clone());
let expected_res: transaction::Result<()> = Err(TransactionError::InstructionError(
0,
InstructionError::CustomError(1),
InstructionError::Custom(1),
));
let json: Value = serde_json::from_str(&res.unwrap()).unwrap();
let result: Option<TransactionStatus> =
Expand Down Expand Up @@ -2614,14 +2614,14 @@ pub mod tests {
meta.err,
Some(TransactionError::InstructionError(
0,
InstructionError::CustomError(1)
InstructionError::Custom(1)
))
);
assert_eq!(
meta.status,
Err(TransactionError::InstructionError(
0,
InstructionError::CustomError(1)
InstructionError::Custom(1)
))
);
} else {
Expand Down Expand Up @@ -2658,14 +2658,14 @@ pub mod tests {
meta.err,
Some(TransactionError::InstructionError(
0,
InstructionError::CustomError(1)
InstructionError::Custom(1)
))
);
assert_eq!(
meta.status,
Err(TransactionError::InstructionError(
0,
InstructionError::CustomError(1)
InstructionError::Custom(1)
))
);
} else {
Expand Down
2 changes: 1 addition & 1 deletion programs/bpf/rust/error_handling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub enum MyError {
}
impl From<MyError> for ProgramError {
fn from(e: MyError) -> Self {
ProgramError::CustomError(e as u32)
ProgramError::Custom(e as u32)
}
}
impl<T> DecodeError<T> for MyError {
Expand Down
4 changes: 2 additions & 2 deletions programs/bpf/tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,14 @@ mod bpf {
let result = bank_client.send_instruction(&mint_keypair, instruction);
assert_eq!(
result.unwrap_err().unwrap(),
TransactionError::InstructionError(0, InstructionError::CustomError(0))
TransactionError::InstructionError(0, InstructionError::Custom(0))
);

let instruction = Instruction::new(program_id, &4u8, account_metas.clone());
let result = bank_client.send_instruction(&mint_keypair, instruction);
assert_eq!(
result.unwrap_err().unwrap(),
TransactionError::InstructionError(0, InstructionError::CustomError(42))
TransactionError::InstructionError(0, InstructionError::Custom(42))
);

let instruction = Instruction::new(program_id, &5u8, account_metas.clone());
Expand Down
2 changes: 1 addition & 1 deletion programs/budget/src/budget_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ mod tests {
.unwrap(),
TransactionError::InstructionError(
0,
InstructionError::CustomError(BudgetError::DestinationMissing as u32)
InstructionError::Custom(BudgetError::DestinationMissing as u32)
)
);
assert_eq!(bank_client.get_balance(&alice_pubkey).unwrap(), 1);
Expand Down
2 changes: 1 addition & 1 deletion programs/failure/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ fn process_instruction(
_keyed_accounts: &[KeyedAccount],
_data: &[u8],
) -> Result<(), InstructionError> {
Err(InstructionError::CustomError(0))
Err(InstructionError::Custom(0))
}
2 changes: 1 addition & 1 deletion programs/failure/tests/failure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ fn test_program_native_failure() {
.send_instruction(&alice_keypair, instruction)
.unwrap_err()
.unwrap(),
TransactionError::InstructionError(0, InstructionError::CustomError(0))
TransactionError::InstructionError(0, InstructionError::Custom(0))
);
}
40 changes: 1 addition & 39 deletions programs/librapay/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions programs/librapay/src/librapay_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,8 @@ mod tests {
fn create_bank(lamports: u64) -> (Arc<Bank>, Keypair, Keypair, Pubkey, Pubkey) {
let (mut genesis_config, mint) = create_genesis_config(lamports);
genesis_config.rent.lamports_per_byte_year = 0;
<<<<<<< HEAD
CriesofCarrots marked this conversation as resolved.
Show resolved Hide resolved
let mut bank = Bank::new(&genesis_config);
bank.add_instruction_processor(
solana_sdk::move_loader::id(),
MoveProcessor::process_instruction,
);
=======
let bank = Bank::new(&genesis_config);
bank.add_native_program("solana_move_loader_program", &solana_sdk::move_loader::id());
>>>>>>> efad19318... Make default programs static (#9717)
let shared_bank = Arc::new(bank);
let bank_client = BankClient::new_shared(&shared_bank);
let genesis_pubkey = create_genesis(&mint, &bank_client, 1_000_000);
Expand Down
4 changes: 2 additions & 2 deletions programs/move_loader/src/error_mappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ pub fn map_failure_error(err: failure::Error) -> InstructionError {
}

pub fn map_err_vm_status(status: VMStatus) -> InstructionError {
// Attempt to map the StatusCode (repr(u64)) to a u32 for CustomError.
// Attempt to map the StatusCode (repr(u64)) to a u32 for Custom.
// The only defined StatusCode that fails is StatusCode::UNKNOWN_ERROR
match <StatusCode as Into<u64>>::into(status.major_status).try_into() {
Ok(u) => InstructionError::CustomError(u),
Ok(u) => InstructionError::Custom(u),
Err(_) => InstructionError::InvalidError,
}
}
34 changes: 9 additions & 25 deletions programs/move_loader/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,7 @@ mod tests {
let code = "main() { return; }";
let sender_address = AccountAddress::default();
let script = LibraAccount::create_script(&sender_address, code, vec![]);
let keyed_accounts = vec![
KeyedAccount::new(&script.key, true, &script.account),
];
let keyed_accounts = vec![KeyedAccount::new(&script.key, true, &script.account)];
MoveProcessor::do_finalize(&keyed_accounts).unwrap();
let _ = MoveProcessor::deserialize_verified_script(&script.account.borrow().data).unwrap();
}
Expand Down Expand Up @@ -551,9 +549,7 @@ mod tests {
let script = LibraAccount::create_script(&sender_address, code, vec![]);
let genesis = LibraAccount::create_genesis(1_000_000_000);

let keyed_accounts = vec![
KeyedAccount::new(&script.key, true, &script.account),
];
let keyed_accounts = vec![KeyedAccount::new(&script.key, true, &script.account)];

MoveProcessor::do_finalize(&keyed_accounts).unwrap();

Expand All @@ -578,9 +574,7 @@ mod tests {
}
";
let module = LibraAccount::create_module(code, vec![]);
let keyed_accounts = vec![
KeyedAccount::new(&module.key, true, &module.account),
];
let keyed_accounts = vec![KeyedAccount::new(&module.key, true, &module.account)];
keyed_accounts[0]
.account
.borrow_mut()
Expand All @@ -604,9 +598,7 @@ mod tests {
let script = LibraAccount::create_script(&sender_address, code, vec![]);
let genesis = LibraAccount::create_genesis(1_000_000_000);

let keyed_accounts = vec![
KeyedAccount::new(&script.key, true, &script.account),
];
let keyed_accounts = vec![KeyedAccount::new(&script.key, true, &script.account)];

MoveProcessor::do_finalize(&keyed_accounts).unwrap();

Expand All @@ -622,7 +614,7 @@ mod tests {
"main".to_string(),
vec![],
),
Err(InstructionError::CustomError(4002))
Err(InstructionError::Custom(4002))
);
}

Expand Down Expand Up @@ -676,9 +668,7 @@ mod tests {
let script = LibraAccount::create_script(&genesis.address, code, vec![]);
let payee = LibraAccount::create_unallocated(BIG_ENOUGH);

let keyed_accounts = vec![
KeyedAccount::new(&script.key, true, &script.account),
];
let keyed_accounts = vec![KeyedAccount::new(&script.key, true, &script.account)];

MoveProcessor::do_finalize(&keyed_accounts).unwrap();

Expand Down Expand Up @@ -731,9 +721,7 @@ mod tests {
);
let module = LibraAccount::create_module(&code, vec![]);

let keyed_accounts = vec![
KeyedAccount::new(&module.key, true, &module.account),
];
let keyed_accounts = vec![KeyedAccount::new(&module.key, true, &module.account)];
keyed_accounts[0]
.account
.borrow_mut()
Expand Down Expand Up @@ -774,9 +762,7 @@ mod tests {
);
let payee = LibraAccount::create_unallocated(BIG_ENOUGH);

let keyed_accounts = vec![
KeyedAccount::new(&script.key, true, &script.account),
];
let keyed_accounts = vec![KeyedAccount::new(&script.key, true, &script.account)];

MoveProcessor::do_finalize(&keyed_accounts).unwrap();

Expand Down Expand Up @@ -821,9 +807,7 @@ mod tests {
let script = LibraAccount::create_script(&genesis.address.clone(), code, vec![]);
let payee = LibraAccount::create_unallocated(BIG_ENOUGH);

let keyed_accounts = vec![
KeyedAccount::new(&script.key, true, &script.account),
];
let keyed_accounts = vec![KeyedAccount::new(&script.key, true, &script.account)];

MoveProcessor::do_finalize(&keyed_accounts).unwrap();

Expand Down
4 changes: 2 additions & 2 deletions programs/stake/src/stake_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ mod tests {
where
T: 'static + std::error::Error + DecodeError<T> + FromPrimitive,
{
if let InstructionError::CustomError(code) = err {
if let InstructionError::Custom(code) = err {
let specific_error: T = T::decode_custom_error_to_enum(code).unwrap();
format!(
"{:?}: {}::{:?} - {}",
Expand All @@ -759,7 +759,7 @@ mod tests {
}
}
assert_eq!(
"CustomError(0): StakeError::NoCreditsToRedeem - not enough credits to redeem",
"Custom(0): StakeError::NoCreditsToRedeem - not enough credits to redeem",
pretty_err::<StakeError>(StakeError::NoCreditsToRedeem.into())
)
}
Expand Down
Loading