cli: improve error messages in generated Rust test template (ANCHOR_WALLET, program id)#4245
Conversation
|
Someone is attempting to deploy a commit to the Solana Foundation Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
This PR improves error handling in the generated Rust unit test template by replacing bare unwrap() calls with more descriptive error messages using expect() and unwrap_or_else(). The changes help developers quickly identify and fix issues related to missing or invalid environment variables, program IDs, and transaction failures.
Changes:
- Replaced
unwrap()withexpect()for ANCHOR_WALLET environment variable lookup with clear guidance message - Added descriptive panic messages for keypair file reading, program ID parsing, program client loading, and transaction sending failures
- Changed
Pubkey::try_from()toPubkey::from_str()(both are valid,from_stris more idiomatic with theFromStrtrait import)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "ANCHOR_WALLET must be set to a keypair path (e.g. ~/.config/solana/id.json)", | ||
| ); | ||
| let payer = read_keypair_file(&anchor_wallet).unwrap_or_else(|e| { | ||
| panic!("Failed to read keypair at $ANCHOR_WALLET ({anchor_wallet}): {e}") |
There was a problem hiding this comment.
The error message uses $ANCHOR_WALLET which is shell syntax for referencing an environment variable, but in this context, it's confusing since the actual path is already being displayed via the {anchor_wallet} interpolation. Consider removing the $ prefix and just say "Failed to read keypair at ANCHOR_WALLET" or "Failed to read keypair from ANCHOR_WALLET" to make it clearer that ANCHOR_WALLET is the environment variable name, not a shell expansion.
| panic!("Failed to read keypair at $ANCHOR_WALLET ({anchor_wallet}): {e}") | |
| panic!("Failed to read keypair at ANCHOR_WALLET ({anchor_wallet}): {e}") |
|
Duplicate of #4243 |
Same behavior, clearer failures: the generated Rust unit test template now uses actionable messages instead of bare
unwrap()s (missing$ANCHOR_WALLET, invalid program id string, failing to load program client, failing to send tx).