diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-05-28 12:46:01 +0200 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@atos.net> | 2021-05-31 11:38:53 +0200 |
commit | 55715ffb14cd24a27fd70c0ad4154eedc6251976 (patch) | |
tree | ffe5affe51665cf2b906d0be7b3060d0078c4bb6 | |
parent | 45806c89605c155df992c1e5e9917f315e9fa495 (diff) |
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 <matthias.beyer@atos.net>
Tested-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r-- | src/endpoint/scheduler.rs | 3 | ||||
-rw-r--r-- | 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::<Result<Vec<String>>>()? .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<String> { + 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)] |