Skip to content

Commit

Permalink
fix: return default version if canonicalize fails (#1058)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquacash5 authored Jan 20, 2024
1 parent d6c132a commit 734df47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-pumpkins-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fnm": patch
---

fix: return default version if canonicalize fails
9 changes: 6 additions & 3 deletions src/default_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use crate::version::Version;
use std::str::FromStr;

pub fn find_default_version(config: &FnmConfig) -> Option<Version> {
let version_path = config.default_version_dir().canonicalize().ok()?;
let file_name = version_path.parent()?.file_name()?;
Version::from_str(file_name.to_str()?).ok()?.into()
if let Ok(version_path) = config.default_version_dir().canonicalize() {
let file_name = version_path.parent()?.file_name()?;
Version::from_str(file_name.to_str()?).ok()?.into()
} else {
Some(Version::Alias("default".into()))
}
}

0 comments on commit 734df47

Please sign in to comment.