Skip to content

Commit

Permalink
client: Remove std::process::exit usage (#3544)
Browse files Browse the repository at this point in the history
  • Loading branch information
acheroncrypto authored Feb 7, 2025
1 parent 13a6df9 commit 16e166c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- idl: Fix missing `program::seed` resolution ([#3474](https://github.com/coral-xyz/anchor/pull/3474)).
- lang: Fix adding `derive`s and `repr`s to type alias definitions in `declare_program!` ([#3504](https://github.com/coral-xyz/anchor/pull/3504)).
- idl: Fix using constant identifiers as generic arguments ([#3522](https://github.com/coral-xyz/anchor/pull/3522)).
- client: Remove `std::process::exit` usage ([#3544](https://github.com/coral-xyz/anchor/pull/3544)).

### Breaking

Expand Down
16 changes: 7 additions & 9 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ impl<C: Deref<Target = impl Signer> + Clone> Program<C> {
signature: logs.value.signature.parse().unwrap(),
slot: logs.context.slot,
};
let events = parse_logs_response(logs, &program_id_str);
let events = parse_logs_response(logs, &program_id_str)?;
for e in events {
f(&ctx, e);
}
Expand Down Expand Up @@ -672,7 +672,7 @@ impl<C: Deref<Target = impl Signer> + Clone, S: AsSigner> RequestBuilder<'_, C,
fn parse_logs_response<T: anchor_lang::Event + anchor_lang::AnchorDeserialize>(
logs: RpcResponse<RpcLogsResponse>,
program_id_str: &str,
) -> Vec<T> {
) -> Result<Vec<T>, ClientError> {
let mut logs = &logs.value.logs[..];
let mut events: Vec<T> = Vec::new();
if !logs.is_empty() {
Expand All @@ -685,10 +685,7 @@ fn parse_logs_response<T: anchor_lang::Event + anchor_lang::AnchorDeserialize>(
// Parse the log.
let (event, new_program, did_pop) = {
if program_id_str == execution.program() {
handle_program_log(program_id_str, l).unwrap_or_else(|e| {
println!("Unable to parse log: {e}");
std::process::exit(1);
})
handle_program_log(program_id_str, l)?
} else {
let (program, did_pop) = handle_system_log(program_id_str, l);
(None, program, did_pop)
Expand Down Expand Up @@ -727,7 +724,7 @@ fn parse_logs_response<T: anchor_lang::Event + anchor_lang::AnchorDeserialize>(
}
}
}
events
Ok(events)
}

#[cfg(test)]
Expand Down Expand Up @@ -856,7 +853,7 @@ mod tests {

// No events returned here. Just ensuring that the function doesn't panic
// due an incorrectly emptied stack.
let _: Vec<MockEvent> = parse_logs_response(
parse_logs_response::<MockEvent>(
RpcResponse {
context: RpcResponseContext::new(0),
value: RpcLogsResponse {
Expand All @@ -866,7 +863,8 @@ mod tests {
},
},
program_id_str,
);
)
.unwrap();

Ok(())
}
Expand Down

0 comments on commit 16e166c

Please sign in to comment.