diff options
| author | 2025-01-05 04:39:18 -0600 | |
|---|---|---|
| committer | 2025-01-05 04:39:18 -0600 | |
| commit | a757414560aba4247eb0bd93cf954968fd006f7c (patch) | |
| tree | 7523186408e3ad85706e9c1e1ca2070e9660ee20 /src/launcher | |
| parent | moo (diff) | |
idr what I changed
Diffstat (limited to 'src/launcher')
| -rw-r--r-- | src/launcher/version.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/launcher/version.rs b/src/launcher/version.rs index 08c3bb5..f4cdd6c 100644 --- a/src/launcher/version.rs +++ b/src/launcher/version.rs @@ -190,12 +190,31 @@ impl<'a, T: Into<VersionResult<'a>>> From<Option<T>> for VersionResult<'a> { } } +#[derive(Debug)] pub enum VersionResolveError { - InheritanceLoop, + InheritanceLoop(String), MissingVersion(String), Unknown(Box<dyn Error>) } +impl Display for VersionResolveError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + VersionResolveError::InheritanceLoop(s) => { + write!(f, "inheritance loop (saw {s} twice)") + }, + VersionResolveError::MissingVersion(s) => { + write!(f, "unknown version {s}") + }, + VersionResolveError::Unknown(err) => { + write!(f, "unknown error: {err}") + } + } + } +} + +impl Error for VersionResolveError {} + impl VersionList { pub async fn online(home: &Path) -> Result<VersionList, Box<dyn Error>> { let remote = RemoteVersionList::new().await?; @@ -262,6 +281,10 @@ impl VersionList { let mut inherit = inherit.clone(); loop { + if seen.insert(inherit.clone()) { + return Err(VersionResolveError::InheritanceLoop(inherit)); + } + let inherited_ver = match self.get_version_lazy(inherit.as_str()) { VersionResult::Complete(v) => Cow::Borrowed(v), VersionResult::Remote(v) => |
