launcher: say which folders were checked when Minecraft is not found

Prepare used to stop with "Minecraft 26.3 is not in <dir>. Play 26.3 once from
the official launcher, or choose another folder." followed by an unrelated log
line ("Checking Java and your Minecraft install"). It now lists every folder it
looked in with what each one lacks (no such folder, no versions/26.3/26.3.json,
no 26.3.jar) and the two ways out, one per line. A missing client jar is caught
here too, instead of later inside horizon-prepare.

Only a preparer process's "Exited with ..." gets the last log line appended;
the launcher's own errors are full sentences.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-16 00:24:43 +02:00
parent 5350f3465b
commit 561efb340e
2 changed files with 76 additions and 8 deletions
+67 -5
View File
@@ -644,6 +644,43 @@ fn preparer_binary(dir: &Path) -> Option<PathBuf> {
binary.is_file().then_some(binary)
}
/// What a Minecraft folder lacks of `version`'s files in the official launcher's layout, or
/// None when it has them.
fn missing_game_files(minecraft: &Path, version: &str) -> Option<String> {
if !minecraft.is_dir() {
return Some("the folder doesn't exist".into());
}
let files = [format!("{version}.json"), format!("{version}.jar")];
let missing: Vec<String> = files
.iter()
.filter(|file| {
!minecraft
.join("versions")
.join(version)
.join(file)
.is_file()
})
.map(|file| format!("versions/{version}/{file}"))
.collect();
(!missing.is_empty()).then(|| format!("no {}", missing.join(" or ")))
}
/// The error when no folder has Minecraft `version`: every folder looked in with what it
/// lacks, and what the player can do about it (#419).
fn not_found(version: &str, checked: &[(PathBuf, String)]) -> String {
let mut text = format!("Minecraft {version} was not found. Horizon looked in:");
for (dir, missing) in checked {
text += &format!("\n {} ({missing})", dir.display());
}
text += &format!(
"\nTo fix it:\n \
• Play {version} once in the official Minecraft launcher, then prepare again.\n \
• Or choose the folder where your launcher keeps Minecraft {version} (Minecraft folder › \
Choose… in the launcher, --minecraft on the command line)."
);
text
}
/// Checks what the preparation needs and picks how to run it. PLAY.txt describes the same
/// steps: the player's own launcher install, the server jar from that version's own json, and
/// Java (and Python, for versions before horizon-prepare).
@@ -655,11 +692,10 @@ pub fn preparer(tag: &str, minecraft: &Path, log: &dyn Fn(String)) -> Result<Pre
.join("versions")
.join(&version)
.join(format!("{version}.json"));
if !reused && !manifest.exists() {
return Err(format!(
"Minecraft {version} is not in {}. Play {version} once from the official launcher, or choose another folder.",
minecraft.display()
));
if !reused {
if let Some(missing) = missing_game_files(minecraft, &version) {
return Err(not_found(&version, &[(minecraft.to_path_buf(), missing)]));
}
}
let binary = preparer_binary(&dir);
let python = if binary.is_some() {
@@ -1684,6 +1720,32 @@ mod tests {
use super::*;
use std::cmp::Ordering::*;
#[test]
fn a_folder_without_the_game_says_what_it_lacks_and_what_to_do() {
let dir = std::env::temp_dir().join(format!("horizon-missing-{}", std::process::id()));
let _ = fs::remove_dir_all(&dir);
assert_eq!(
missing_game_files(&dir, "26.3").as_deref(),
Some("the folder doesn't exist")
);
fs::create_dir_all(dir.join("versions/26.3")).unwrap();
assert_eq!(
missing_game_files(&dir, "26.3").as_deref(),
Some("no versions/26.3/26.3.json or versions/26.3/26.3.jar")
);
fs::write(dir.join("versions/26.3/26.3.json"), "{}").unwrap();
let missing = missing_game_files(&dir, "26.3").unwrap();
assert_eq!(missing, "no versions/26.3/26.3.jar");
let error = not_found("26.3", &[(dir.clone(), missing)]);
assert!(error.starts_with("Minecraft 26.3 was not found. Horizon looked in:\n"));
assert!(error.contains(&format!("{} (no versions/26.3/26.3.jar)", dir.display())));
assert!(error.contains("Play 26.3 once in the official Minecraft launcher"));
assert!(error.contains("--minecraft on the command line"));
fs::write(dir.join("versions/26.3/26.3.jar"), "jar").unwrap();
assert_eq!(missing_game_files(&dir, "26.3"), None);
fs::remove_dir_all(&dir).unwrap();
}
#[test]
fn the_game_plays_under_its_own_audio_stream_name() {
if std::env::var_os("PIPEWIRE_PROPS").is_some() {
+9 -3
View File
@@ -501,9 +501,15 @@ impl Launcher {
if let (None, Some(started)) = (&error, self.prepare_started.take()) {
self.perf.record_since("launcher.prepare_ms", started);
}
// A preparer process's exit status says little, so its last line
// follows; the launcher's own errors are full sentences already.
self.prepare_error = error.map(|e| {
let tail =
self.prepare_log.iter().rev().find(|l| !l.trim().is_empty());
let tail = self
.prepare_log
.iter()
.rev()
.find(|l| !l.trim().is_empty())
.filter(|_| e.starts_with("Exited with"));
tail.map_or(e.clone(), |t| format!("{e}: {t}"))
});
}
@@ -1436,7 +1442,7 @@ impl Launcher {
let minecraft = self.settings.minecraft_dir.as_deref().map_or_else(
|| {
div()
.child("Not found. Choose the official launcher's game folder.")
.child("Not found. Choose the folder where your launcher keeps Minecraft.")
.into_any_element()
},
|p| {