Skip to content

Commit b8780dc

Browse files
committed
feat: enhance error handling and path resolution in analyzer and installer modules
1 parent 41113c2 commit b8780dc

8 files changed

Lines changed: 293 additions & 120 deletions

File tree

src-tauri/src/analysis/analyzer.rs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,29 +96,39 @@ impl Analyzer {
9696
Ok(staged_source.to_string_lossy().to_string())
9797
}
9898

99-
fn resolve_stable_source_path(&self, item: &DetectedItem) -> Option<String> {
100-
if item.addon_type != AddonType::LuaScript {
99+
fn canonicalize_existing_source_path(&self, source: &Path) -> Option<String> {
100+
if !source.exists() {
101101
return None;
102102
}
103103

104+
source
105+
.canonicalize()
106+
.ok()
107+
.map(|path| path.to_string_lossy().to_string())
108+
}
109+
110+
fn resolve_stable_source_path(&self, item: &DetectedItem) -> Option<String> {
104111
let source = Path::new(&item.path);
105-
if !source.is_file() || crate::archive_input::detect_archive_format(source).is_some() {
106-
return None;
107-
}
108112

109-
match self.stage_standalone_lua_source(source, &item.companion_paths) {
110-
Ok(staged) => Some(staged),
111-
Err(e) => {
112-
logger::log_error(
113-
&format!(
114-
"Failed to stage standalone Lua source {:?}, continuing with original path: {}",
115-
source, e
116-
),
117-
Some("analyzer"),
118-
);
119-
None
113+
if item.addon_type == AddonType::LuaScript
114+
&& source.is_file()
115+
&& crate::archive_input::detect_archive_format(source).is_none()
116+
{
117+
match self.stage_standalone_lua_source(source, &item.companion_paths) {
118+
Ok(staged) => return Some(staged),
119+
Err(e) => {
120+
logger::log_error(
121+
&format!(
122+
"Failed to stage standalone Lua source {:?}, falling back to canonical source path: {}",
123+
source, e
124+
),
125+
Some("analyzer"),
126+
);
127+
}
120128
}
121129
}
130+
131+
self.canonicalize_existing_source_path(source)
122132
}
123133

124134
/// Analyze a list of paths and return installation tasks

src-tauri/src/analysis/hash_collector.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ impl HashCollector {
3131
return Ok(HashMap::new());
3232
}
3333

34-
let source = Path::new(&task.source_path);
34+
let source = task
35+
.resolved_source_path
36+
.as_deref()
37+
.map(Path::new)
38+
.unwrap_or_else(|| Path::new(&task.source_path));
3539

3640
if source.is_dir() {
3741
// Direct directory: compute SHA256 for all files

src-tauri/src/install/installer/handlers.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,8 @@ impl Installer {
608608
}
609609

610610
Err(anyhow::anyhow!(
611-
"Lua source path is neither file nor directory: {:?}",
612-
source
611+
"Source path is not a regular file or directory: {}",
612+
source.display()
613613
))
614614
}
615615

@@ -764,7 +764,17 @@ impl Installer {
764764
self.copy_single_file_with_progress(source, target, ctx)?;
765765
}
766766
} else {
767-
return Err(anyhow::anyhow!("Source path is neither file nor directory"));
767+
if !source.exists() {
768+
return Err(anyhow::anyhow!(
769+
"Source file is no longer available: {}",
770+
source.display()
771+
));
772+
}
773+
774+
return Err(anyhow::anyhow!(
775+
"Source path is not a regular file or directory: {}",
776+
source.display()
777+
));
768778
}
769779
Ok(())
770780
}

src-tauri/src/lib.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,12 @@ fn launch_xplane(xplane_path: String, args: Option<Vec<String>>) -> Result<(), S
15711571
// Return a structured error that frontend can handle
15721572
return Err(format!("ELEVATION_REQUIRED:{}", exe_path.display()));
15731573
}
1574+
Err(e) if e.raw_os_error() == Some(193) => {
1575+
return Err(
1576+
"Selected X-Plane executable is not a valid Windows executable. Check that the X-Plane path points to the real X-Plane installation."
1577+
.to_string(),
1578+
);
1579+
}
15741580
Err(e) => {
15751581
return Err(format!("Failed to launch X-Plane: {}", e));
15761582
}
@@ -1599,7 +1605,14 @@ fn launch_xplane(xplane_path: String, args: Option<Vec<String>>) -> Result<(), S
15991605
std::process::Command::new(exe_path)
16001606
.args(&extra_args)
16011607
.spawn()
1602-
.map_err(|e| format!("Failed to launch X-Plane: {}", e))?;
1608+
.map_err(|e| {
1609+
if e.raw_os_error() == Some(8) {
1610+
"Selected X-Plane executable is not runnable on this system (Exec format error). Check that the X-Plane path points to the correct executable for your platform and that the file has execute permission."
1611+
.to_string()
1612+
} else {
1613+
format!("Failed to launch X-Plane: {}", e)
1614+
}
1615+
})?;
16031616
}
16041617

16051618
logger::log_info("X-Plane launched", Some("app"));

0 commit comments

Comments
 (0)