Skip to content

Commit

Permalink
cli: Ignore non semver solana/agave releases to avoid panic (#3432)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arrowana authored Dec 18, 2024
1 parent 5767365 commit 2233ee7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- lang: Require `zero` accounts to be unique ([#3409](https://github.com/coral-xyz/anchor/pull/3409)).
- lang: Deduplicate `zero` accounts against `init` accounts ([#3422](https://github.com/coral-xyz/anchor/pull/3422)).
- cli: Fix custom `provider.cluster` ([#3428](https://github.com/coral-xyz/anchor/pull/3428)).
- cli: Ignore non semver solana/agave releases to avoid panic ([#3432](https://github.com/coral-xyz/anchor/pull/3432)).

### Breaking

Expand Down
27 changes: 14 additions & 13 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,16 +556,16 @@ fn override_toolchain(cfg_override: &ConfigOverride) -> Result<RestoreToolchainC

let cfg = Config::discover(cfg_override)?;
if let Some(cfg) = cfg {
fn parse_version(text: &str) -> String {
Regex::new(r"(\d+\.\d+\.\S+)")
.unwrap()
.captures_iter(text)
.next()
.unwrap()
.get(0)
.unwrap()
.as_str()
.to_string()
fn parse_version(text: &str) -> Option<String> {
Some(
Regex::new(r"(\d+\.\d+\.\S+)")
.unwrap()
.captures_iter(text)
.next()?
.get(0)?
.as_str()
.to_string(),
)
}

fn get_current_version(cmd_name: &str) -> Result<String> {
Expand All @@ -577,8 +577,8 @@ fn override_toolchain(cfg_override: &ConfigOverride) -> Result<RestoreToolchainC
}

let output_version = std::str::from_utf8(&output.stdout)?;
let version = parse_version(output_version);
Ok(version)
parse_version(output_version)
.ok_or_else(|| anyhow!("Failed to parse the version of `{cmd_name}`"))
}

if let Some(solana_version) = &cfg.toolchain.solana_version {
Expand Down Expand Up @@ -635,7 +635,8 @@ fn override_toolchain(cfg_override: &ConfigOverride) -> Result<RestoreToolchainC
// Hide the installation progress if the version is already installed
let is_installed = std::str::from_utf8(&output.stdout)?
.lines()
.any(|line| parse_version(line) == version);
.filter_map(parse_version)
.any(|line_version| line_version == version);
let (stderr, stdout) = if is_installed {
(Stdio::null(), Stdio::null())
} else {
Expand Down

0 comments on commit 2233ee7

Please sign in to comment.