From b1ee6611b839f31e9691263f70cc5e008852df60 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Thu, 7 May 2026 11:17:37 +0200 Subject: [PATCH] Enhance generation logging and status reporting for map generation --- src-tauri/src/main.rs | 117 ++++++++++++++++++++++++++++++------------ 1 file changed, 85 insertions(+), 32 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index d78934e..a053479 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -390,44 +390,79 @@ async fn generate_map( let out_dir = output_dir(&root)?; let script = script_path(&root)?; let python = python_binary(&root); + let log_path = generation_log_path(&root, &prompt_clone)?; + let log_path_display = log_path.to_string_lossy().to_string(); + let mut log_file = File::create(&log_path) + .map_err(|e| format!("Failed to create generation log: {e}"))?; - let mut cmd = Command::new(python); - cmd.current_dir(&root) - .arg(script.as_os_str()) - .arg("--prompt") - .arg(prompt_clone) - .arg("--output-dir") - .arg(&out_dir) - .arg("--work-dir") - .arg(root.to_string_lossy().to_string()) - .arg("--upscale") - .arg(upscale) - .arg("--steps") - .arg(steps.to_string()) - .arg("--guidance") - .arg(guidance.to_string()) - .arg("--width") - .arg(width.to_string()) - .arg("--height") - .arg(height.to_string()) - .arg("--scheduler") - .arg(scheduler) - .arg("--model-path") - .arg(model_path) - .arg("--base-model") - .arg(base_model) - .arg("--vae-model") - .arg(vae_model) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()); + let mut args = vec![ + script.to_string_lossy().to_string(), + "--prompt".to_string(), + prompt_clone.clone(), + "--output-dir".to_string(), + out_dir.to_string_lossy().to_string(), + "--work-dir".to_string(), + root.to_string_lossy().to_string(), + "--upscale".to_string(), + upscale, + "--steps".to_string(), + steps.to_string(), + "--guidance".to_string(), + guidance.to_string(), + "--width".to_string(), + width.to_string(), + "--height".to_string(), + height.to_string(), + "--scheduler".to_string(), + scheduler, + "--model-path".to_string(), + model_path, + "--base-model".to_string(), + base_model, + "--vae-model".to_string(), + vae_model, + ]; if seam_inpaint { - cmd.arg("--seam-inpaint"); + args.push("--seam-inpaint".to_string()); + } + + write_log_line(&mut log_file, "SkymapGen generation log"); + write_log_line( + &mut log_file, + format!("started_unix_ms: {}", unix_timestamp_millis()), + ); + write_log_line(&mut log_file, format!("cwd: {}", root.to_string_lossy())); + write_log_line(&mut log_file, format!("log_path: {log_path_display}")); + write_log_line(&mut log_file, format!("prompt: {prompt_clone}")); + write_log_line(&mut log_file, format!("steps: {steps}")); + write_log_line(&mut log_file, format!("guidance: {guidance}")); + write_log_line(&mut log_file, format!("size: {width}x{height}")); + write_log_line(&mut log_file, format!("seam_inpaint: {seam_inpaint}")); + write_log_line(&mut log_file, "command:"); + write_log_line( + &mut log_file, + format!(" program: {}", python.to_string_lossy()), + ); + for arg in &args { + write_log_line(&mut log_file, format!(" arg: {arg}")); + } + write_log_line(&mut log_file, ""); + + let mut cmd = Command::new(&python); + cmd.current_dir(&root) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()); + for arg in &args { + cmd.arg(arg); } let mut child = cmd .spawn() .map_err(|e| format!("Failed to start generator: {e}"))?; + write_log_line(&mut log_file, format!("pid: {}", child.id())); + write_log_line(&mut log_file, ""); + write_log_line(&mut log_file, "stdout:"); { let mut active = active_generation_pid @@ -466,6 +501,7 @@ async fn generate_map( > 0 { let trimmed = line.trim_end().to_string(); + write_log_line(&mut log_file, format!(" {trimmed}")); if let Some(json_str) = trimmed.strip_prefix("PROGRESS ") { if let Ok(val) = serde_json::from_str::(json_str) { let _ = window.emit("gen-progress", val); @@ -480,13 +516,24 @@ async fn generate_map( .wait() .map_err(|e| format!("Failed to wait for generator: {e}"))?; let stderr_output = stderr_handle.join().unwrap_or_default(); + write_log_line(&mut log_file, ""); + write_log_line(&mut log_file, "stderr:"); + for line in stderr_output.lines() { + write_log_line(&mut log_file, format!(" {line}")); + } + write_log_line(&mut log_file, ""); + write_log_line(&mut log_file, format!("exit_status: {status}")); if cancel_generation_requested.load(Ordering::SeqCst) { - return Err("Generation cancelled".to_string()); + write_log_line(&mut log_file, "result: cancelled"); + return Err(format!("Generation cancelled. Log: {log_path_display}")); } if !status.success() { - return Err(format!("Generator failed: {stderr_output}")); + write_log_line(&mut log_file, "result: failed"); + return Err(format!( + "Generator failed. Log: {log_path_display}\n{stderr_output}" + )); } let path_line = @@ -497,8 +544,14 @@ async fn generate_map( } else { out_dir.join(path) }; + write_log_line(&mut log_file, format!("result: success")); + write_log_line( + &mut log_file, + format!("output_path: {}", resolved.to_string_lossy()), + ); Ok(GenerateResult { output_path: resolved.to_string_lossy().to_string(), + log_path: log_path_display, }) })();