]> git.proxmox.com Git - pve-installer.git/commitdiff
tui: install_progress: write low-level non-JSON messages to separate file
authorChristoph Heiss <c.heiss@proxmox.com>
Mon, 26 Feb 2024 14:18:38 +0000 (15:18 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 27 Feb 2024 15:43:42 +0000 (16:43 +0100)
The low-level installer prints quite a few messages during the install
to its stdout which are not JSON-formatted and thus parseable.

Thus catch them early and write them to `/tmp/install-low-level.log`, to
avoid polluting the log tty at /dev/tty2 with mostly useless parse
errors.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
proxmox-tui-installer/src/views/install_progress.rs

index 4626fe4fb8769a5c6bbcafd86a32bf3187c8f392..c2c9ddf926a32e933b37290f5c1c31f7a401727a 100644 (file)
@@ -6,6 +6,7 @@ use cursive::{
 };
 use serde::Deserialize;
 use std::{
+    fs::File,
     io::{BufRead, BufReader, Write},
     sync::{Arc, Mutex},
     thread,
@@ -86,6 +87,9 @@ impl InstallProgressView {
                 .map_err(|err| format!("failed to serialize install config: {err}"))?;
             writeln!(writer).map_err(|err| format!("failed to write install config: {err}"))?;
 
+            let mut lowlevel_log = File::create("/tmp/install-low-level.log")
+                .map_err(|err| format!("failed to open low-level installer logfile: {err}"))?;
+
             let writer = Arc::new(Mutex::new(writer));
 
             for line in reader.lines() {
@@ -94,11 +98,20 @@ impl InstallProgressView {
                     Err(err) => return Err(format!("low-level installer exited early: {err}")),
                 };
 
+                // The low-level installer also spews the output of any command it runs on its
+                // stdout. Use a very simple heuricstic to determine whether it is actually JSON
+                // or not.
+                if !line.starts_with('{') || !line.ends_with('}') {
+                    let _ = writeln!(lowlevel_log, "{}", line);
+                    continue;
+                }
+
                 let msg = match serde_json::from_str::<UiMessage>(&line) {
                     Ok(msg) => msg,
-                    Err(stray) => {
+                    Err(err) => {
                         // Not a fatal error, so don't abort the installation by returning
-                        eprintln!("low-level installer: {stray}");
+                        eprintln!("low-level installer: error while parsing message: '{err}'");
+                        eprintln!("    original message was: '{line}'");
                         continue;
                     }
                 };