Skip to content

Commit

Permalink
rpc-client: Print transaction logs in preflight error (solana-labs#1387)
Browse files Browse the repository at this point in the history
* rpc-client: Print transaction logs in preflight error

* Address feedback

* Update expected error message in program deploy test

* Use a semicolon before the data
  • Loading branch information
joncinque authored May 17, 2024
1 parent 664bf10 commit 4f6dd3d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 8 additions & 2 deletions cli/tests/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,10 @@ fn test_cli_program_upgrade_auto_extend() {
RPC response error -32002: \
Transaction simulation failed: \
Error processing Instruction 0: \
account data too small for instruction [3 log messages]",
account data too small for instruction; 3 log messages:\n \
Program BPFLoaderUpgradeab1e11111111111111111111111 invoke [1]\n \
ProgramData account not large enough\n \
Program BPFLoaderUpgradeab1e11111111111111111111111 failed: account data too small for instruction\n",
);

// Attempt to upgrade the program with a larger program, this time without
Expand Down Expand Up @@ -1147,7 +1150,10 @@ fn test_cli_program_extend_program() {
RPC response error -32002: \
Transaction simulation failed: \
Error processing Instruction 0: \
account data too small for instruction [3 log messages]",
account data too small for instruction; 3 log messages:\n \
Program BPFLoaderUpgradeab1e11111111111111111111111 invoke [1]\n \
ProgramData account not large enough\n \
Program BPFLoaderUpgradeab1e11111111111111111111111 failed: account data too small for instruction\n",
);

// Wait one slot to avoid "Program was deployed in this block already" error
Expand Down
9 changes: 6 additions & 3 deletions rpc-client-api/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,11 @@ impl fmt::Display for RpcResponseErrorData {
if logs.is_empty() {
Ok(())
} else {
// Give the user a hint that there is more useful logging information available...
write!(f, "[{} log messages]", logs.len())
writeln!(f, "{} log messages:", logs.len())?;
for log in logs {
writeln!(f, " {log}")?;
}
Ok(())
}
}
_ => Ok(()),
Expand All @@ -256,7 +259,7 @@ impl fmt::Display for RpcResponseErrorData {
pub enum RpcError {
#[error("RPC request error: {0}")]
RpcRequestError(String),
#[error("RPC response error {code}: {message} {data}")]
#[error("RPC response error {code}: {message}; {data}")]
RpcResponseError {
code: i64,
message: String,
Expand Down

0 comments on commit 4f6dd3d

Please sign in to comment.