Skip to content

Commit 270d3c8

Browse files
committed
Add the affected program address to each InstructionError
1 parent b1cdd3c commit 270d3c8

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

transaction-error/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ solana-frozen-abi-macro = { workspace = true, optional = true }
1717
solana-instruction = { workspace = true, default-features = false, features = [
1818
"std",
1919
] }
20+
solana-pubkey = { workspace = true }
2021
solana-sanitize = { workspace = true }
2122

2223
[features]

transaction-error/src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
use serde_derive::{Deserialize, Serialize};
55
#[cfg(feature = "frozen-abi")]
66
use solana_frozen_abi_macro::{AbiEnumVisitor, AbiExample};
7-
use {core::fmt, solana_instruction::error::InstructionError, solana_sanitize::SanitizeError};
7+
use {
8+
core::fmt, solana_instruction::error::InstructionError, solana_pubkey::Pubkey,
9+
solana_sanitize::SanitizeError,
10+
};
811

912
pub type TransactionResult<T> = Result<T, TransactionError>;
1013

@@ -43,8 +46,10 @@ pub enum TransactionError {
4346
BlockhashNotFound,
4447

4548
/// An error occurred while processing an instruction. The first element of the tuple
46-
/// indicates the instruction index in which the error occurred.
47-
InstructionError(u8, InstructionError),
49+
/// indicates the instruction index in which the error occurred. For avoidance of doubt, the
50+
/// third element indicates the address of the program that raised the error; the error could
51+
/// after all have been raised during a cross-program invocation (ie. in an inner instruction).
52+
InstructionError(u8, InstructionError, Option<Pubkey>),
4853

4954
/// Loader call chain is too deep
5055
CallChainTooDeep,
@@ -163,7 +168,10 @@ impl fmt::Display for TransactionError {
163168
=> f.write_str("This transaction has already been processed"),
164169
Self::BlockhashNotFound
165170
=> f.write_str("Blockhash not found"),
166-
Self::InstructionError(idx, err) => write!(f, "Error processing Instruction {idx}: {err}"),
171+
Self::InstructionError(idx, err, None)
172+
=> write!(f, "Error processing Instruction {idx}: {err}"),
173+
Self::InstructionError(idx, err, Some(program_address))
174+
=> write!(f, "Error processing Instruction {idx}: {err} (from program {program_address})"),
167175
Self::CallChainTooDeep
168176
=> f.write_str("Loader call chain is too deep"),
169177
Self::MissingSignatureForFee

transaction/src/sanitized.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ impl SanitizedTransaction {
302302
TransactionError::InstructionError(
303303
index as u8,
304304
solana_instruction::error::InstructionError::Custom(err as u32),
305+
Some(*program_id),
305306
)
306307
})?;
307308
}

0 commit comments

Comments
 (0)