public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer] tui: install_progress: write low-level non-JSON messages to separate file
Date: Mon, 26 Feb 2024 15:18:38 +0100	[thread overview]
Message-ID: <20240226141943.822479-1-c.heiss@proxmox.com> (raw)

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>
---
Nothing actually critical, but makes the log tty a lot more useful ..

 .../src/views/install_progress.rs               | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/proxmox-tui-installer/src/views/install_progress.rs b/proxmox-tui-installer/src/views/install_progress.rs
index 4626fe4..c2c9ddf 100644
--- a/proxmox-tui-installer/src/views/install_progress.rs
+++ b/proxmox-tui-installer/src/views/install_progress.rs
@@ -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;
                     }
                 };
--
2.43.0





                 reply	other threads:[~2024-02-26 14:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240226141943.822479-1-c.heiss@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal