cli: improve error messages in generated Rust test template#4243
cli: improve error messages in generated Rust test template#4243yukikm wants to merge 1 commit intosolana-foundation:masterfrom
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 the developer experience when using the generated Rust unit test template by replacing generic unwrap() calls with more descriptive error messages. The changes make test failures easier to diagnose by providing clear, actionable panic messages that specify what went wrong (e.g., missing environment variable, invalid program ID, or client creation failure).
Changes:
- Replaced
.unwrap()with.expect()and.unwrap_or_else()calls that provide specific error messages - Changed from
Pubkey::try_from()toPubkey::from_str()(both are valid, butfrom_stris more idiomatic with theFromStrtrait import) - Added contextual information to all error messages to help developers quickly identify and resolve issues
💡 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 variable notation. In Rust panic messages, it's clearer to omit the $ prefix since we're already showing the actual path value in the braces. Consider changing to just ANCHOR_WALLET for consistency with the error message on line 779.
| panic!("Failed to read keypair at $ANCHOR_WALLET ({anchor_wallet}): {e}") | |
| panic!("Failed to read keypair at ANCHOR_WALLET ({anchor_wallet}): {e}") |
Improves developer UX for the generated Rust unit test template by replacing a few
unwrap()s with clearer, actionable panic messages (e.g. missing$ANCHOR_WALLET, invalid program id string, or program client creation failure).This keeps behavior the same (tests still fail fast), but makes failures much easier to diagnose.