diff options
| author | 2025-02-01 00:20:54 -0600 | |
|---|---|---|
| committer | 2025-02-01 00:20:54 -0600 | |
| commit | 6a1bb0980facadcc22cbae27f57782050e7924a1 (patch) | |
| tree | dafdd715f7fc3f42323bd20666bd653a73a30b68 /src/launcher.rs | |
| parent | do clippy stuff and change line endings (diff) | |
random changes
Diffstat (limited to 'src/launcher.rs')
| -rw-r--r-- | src/launcher.rs | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/launcher.rs b/src/launcher.rs index 0f2b442..2836db5 100644 --- a/src/launcher.rs +++ b/src/launcher.rs @@ -45,6 +45,7 @@ use runner::ArgumentType; use strsub::SubFunc; use crate::launcher::download::FileDownload; use crate::launcher::jre::{JavaRuntimeError, JavaRuntimeRepository}; +use crate::launcher::version::VersionError; use crate::version::manifest::VersionType; #[derive(Debug)] @@ -115,8 +116,9 @@ pub enum LaunchError { UnknownInstance(String), // version resolution errors + VersionInit(VersionError), UnknownVersion(String), - LoadVersion(Box<dyn Error>), + LoadVersion(VersionError), ResolveVersion(VersionResolveError), IncompatibleVersion(IncompatibleError), MissingMainClass, @@ -149,6 +151,7 @@ impl Display for LaunchError { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match &self { LaunchError::UnknownInstance(inst) => write!(f, "unknown instance: {inst}"), + LaunchError::VersionInit(e) => write!(f, "initializing version: {e}"), LaunchError::UnknownVersion(id) => write!(f, "unknown version id: {id}"), LaunchError::LoadVersion(e) => write!(f, "error loading remote version: {e}"), LaunchError::ResolveVersion(e) => write!(f, "error resolving remote version: {e}"), @@ -175,7 +178,8 @@ impl Display for LaunchError { impl Error for LaunchError { fn cause(&self) -> Option<&dyn Error> { match &self { - LaunchError::LoadVersion(e) => Some(e.as_ref()), + LaunchError::VersionInit(e) => Some(e), + LaunchError::LoadVersion(e) => Some(e), LaunchError::ResolveVersion(e) => Some(e), LaunchError::IncompatibleVersion(e) => Some(e), LaunchError::LibraryDirError(_, e) => Some(e), @@ -232,23 +236,25 @@ impl FeatureMatcher for ProfileFeatureMatcher<'_> { impl Launcher { // FIXME: more descriptive error type por favor - pub async fn new(home: impl AsRef<Path>, online: bool) -> Result<Launcher, Box<dyn Error>> { + pub async fn new(home: impl AsRef<Path>, online: bool) -> Result<Launcher, LaunchError> { match tokio::fs::create_dir_all(home.as_ref()).await { Err(e) if e.kind() != AlreadyExists => { warn!("Failed to create launcher home directory: {}", e); - return Err(e.into()); + return Err(LaunchError::IO { what: "create launcher home", error: e }); }, _ => () } - let home = fs::canonicalize(home.as_ref()).await?; + let home = fs::canonicalize(home.as_ref()).await + .map_err(|e| LaunchError::IO { what: "resolve home path", error: e })?; + let versions_home = home.join("versions"); debug!("Version list online?: {online}"); let versions = if online { - VersionList::online(versions_home.as_ref()).await? + VersionList::online(versions_home.as_ref()).await.map_err(LaunchError::VersionInit)? } else { - VersionList::offline(versions_home.as_ref()).await? + VersionList::offline(versions_home.as_ref()).await.map_err(LaunchError::VersionInit)? }; let assets_path = home.join("assets"); @@ -263,7 +269,7 @@ impl Launcher { home: home.join("libraries"), natives: home.join("natives") }, - assets: AssetRepository::new(online, &assets_path).await?, + assets: AssetRepository::new(online, &assets_path).await.map_err(|e| LaunchError::IO { what: "setting up assets", error: e })?, java_runtimes, home }) |
