summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-05-28 12:46:01 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-06-01 11:39:37 +0200
commit8e0ba26b15ffb78fa05f1e631bfd12722ddcd31e (patch)
tree06af3002cc6641ae04aab59b696536d0ca44f06f
parent9b47e557a40dab7bd13e92790c4515d05f073157 (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> (cherry picked from commit 55715ffb14cd24a27fd70c0ad4154eedc6251976)
-rw-r--r--src/endpoint/scheduler.rs3
-rw-r--r--src/log/item.rs11
2 files changed, 12 insertions, 2 deletions
diff --git a/src/endpoint/scheduler.rs b/src/endpoint/scheduler.rs
index 5f0882b..384e0e1 100644
--- a/src/endpoint/scheduler.rs
+++ b/src/endpoint/scheduler.rs
@@ -396,8 +396,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 9518479..5bceae1 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;
#[derive(Debug, PartialEq, Eq, Hash)]
@@ -36,6 +37,16 @@ impl LogItem {
LogItem::State(Err(s)) => Ok(Display(format!("#BUTIDO:STATE:ERR:{}", s))),
}
}
+
+ 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)]