Skip to content

cli: improve error messages in generated Rust test template#4243

Open
yukikm wants to merge 1 commit intosolana-foundation:masterfrom
yukikm:fix/better-errors-generated-test
Open

cli: improve error messages in generated Rust test template#4243
yukikm wants to merge 1 commit intosolana-foundation:masterfrom
yukikm:fix/better-errors-generated-test

Conversation

@yukikm
Copy link

@yukikm yukikm commented Feb 15, 2026

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.

Copilot AI review requested due to automatic review settings February 15, 2026 14:46
@vercel
Copy link

vercel bot commented Feb 15, 2026

Someone is attempting to deploy a commit to the Solana Foundation Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() to Pubkey::from_str() (both are valid, but from_str is more idiomatic with the FromStr trait 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}")
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
panic!("Failed to read keypair at $ANCHOR_WALLET ({anchor_wallet}): {e}")
panic!("Failed to read keypair at ANCHOR_WALLET ({anchor_wallet}): {e}")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants