From 55715ffb14cd24a27fd70c0ad4154eedc6251976 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 28 May 2021 12:46:01 +0200 Subject: Fix: Insert shouldn't be done with LogItem::display() This fixes a nasty bug; because we used the LogItem::display() function to build the log string that was put into the database, the database contained _colorized_ log lines. Because of this, our parsing of the log text later (when reading historical data from the database) failed to parse whether the job was successfull or not. The issue was actually introduced in b3a6458ce34e3065192208826b2fc85edd4761f9, where we changed the `LogItem::display()` implementation. With this fix in place, the log text in the database is corrected again (only for new logs that get put into the database). Fixes: b3a6458ce34e3065192208826b2fc85edd4761f9 ("Add color support in LogItem::display() impl") Signed-off-by: Matthias Beyer Tested-by: Matthias Beyer --- src/endpoint/scheduler.rs | 3 +-- src/log/item.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/endpoint/scheduler.rs b/src/endpoint/scheduler.rs index 5a00c99..2374aa9 100644 --- a/src/endpoint/scheduler.rs +++ b/src/endpoint/scheduler.rs @@ -426,8 +426,7 @@ impl<'a> LogReceiver<'a> { Ok({ accu.iter() - .map(crate::log::LogItem::display) - .map_ok(|d| d.to_string()) + .map(crate::log::LogItem::raw) .collect::>>()? .join("\n") }) diff --git a/src/log/item.rs b/src/log/item.rs index 2887841..d49c51b 100644 --- a/src/log/item.rs +++ b/src/log/item.rs @@ -8,6 +8,7 @@ // SPDX-License-Identifier: EPL-2.0 // +use anyhow::Error; use anyhow::Result; use colored::Colorize; @@ -37,6 +38,16 @@ impl LogItem { LogItem::State(Err(s)) => Ok(Display(format!("#BUTIDO:STATE:ERR:{}", s).red())), } } + + pub fn raw(&self) -> Result { + match self { + LogItem::Line(s) => String::from_utf8(s.to_vec()).map_err(Error::from), + LogItem::Progress(u) => Ok(format!("#BUTIDO:PROGRESS:{}", u)), + LogItem::CurrentPhase(p) => Ok(format!("#BUTIDO:PHASE:{}", p)), + LogItem::State(Ok(())) => Ok("#BUTIDO:STATE:OK".to_string()), + LogItem::State(Err(s)) => Ok(format!("#BUTIDO:STATE:ERR:{}", s)), + } + } } #[derive(parse_display::Display)] -- cgit v1.2.3