Skip to content

cli: improve error messages in generated Rust test template (ANCHOR_WALLET, program id)#4245

Closed
yukikm wants to merge 1 commit intosolana-foundation:masterfrom
yukikm:fix/rust-template-better-errors-2
Closed

cli: improve error messages in generated Rust test template (ANCHOR_WALLET, program id)#4245
yukikm wants to merge 1 commit intosolana-foundation:masterfrom
yukikm:fix/rust-template-better-errors-2

Conversation

@yukikm
Copy link

@yukikm yukikm commented Feb 15, 2026

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).

Copilot AI review requested due to automatic review settings February 15, 2026 14:51
@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 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() with expect() 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() to Pubkey::from_str() (both are valid, from_str is more idiomatic with the FromStr trait 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}")
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 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.

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.
@jamie-osec
Copy link
Collaborator

Duplicate of #4243

@jamie-osec jamie-osec marked this as a duplicate of #4243 Feb 16, 2026
@jamie-osec jamie-osec closed this Feb 16, 2026
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.

3 participants