Skip to content

Commit

Permalink
osbuild: do not assume osbuild stage messages have a final \n
Browse files Browse the repository at this point in the history
This commit tweaks the osbuild monitor code to deal correctly
with messages from osbuild stage that may not contain a final
newline. So far the code assumed this and stripped the final
newline when storing the message in the status. But sometimes
there are messages without a final \n (e.g. when messages get
very long). So just put the message in verbatim and let the
caller do a "print" instead of a "println" when processing
the messages (arguably the trim for traces was always strong).
  • Loading branch information
mvo5 committed Feb 7, 2025
1 parent b16c6f1 commit ad627d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions pkg/osbuild/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import (
// and based on what we learn here we may consider tweaking
// the osbuild progress
type Status struct {
// Trace contains a single log line, usually very low-level or
// stage output but useful for e.g. bug reporting. Should in
// general not be displayed to the user but the concatenation
// of all "trace" lines should give the same information as
// running osbuild on a terminal
// Trace contains log lines, usually very low-level or stage
// output but useful for e.g. bug reporting. Should in general
// not be displayed to the user but the concatenation of all
// "trace" lines should give the same information as running
// osbuild on a terminal. It may contain multiple lines and
// may not end with a \n
Trace string

// Message contains a high level user-visible message about
Expand Down Expand Up @@ -106,7 +107,9 @@ func (sr *StatusScanner) Status() (*Status, error) {
if context.Origin == "osbuild.monitor" {
msg = strings.TrimSpace(status.Message)
} else {
trace = strings.TrimSpace(status.Message)
// arbitrary osbuild messages can be very long and
// may not end with a \n so do not assume this
trace = status.Message
}

st := &Status{
Expand Down
4 changes: 2 additions & 2 deletions pkg/osbuild/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestScannerSimple(t *testing.T) {
st, err := scanner.Status()
assert.NoError(t, err)
assert.Equal(t, &osbuild.Status{
Trace: "source/org.osbuild.curl (org.osbuild.curl): Downloaded https://rpmrepo.osbuild.org/v2/mirror/public/f39/f39-x86_64-fedora-20231109/Packages/k/kpartx-0.9.5-2.fc39.x86_64.rpm",
Trace: "source/org.osbuild.curl (org.osbuild.curl): Downloaded https://rpmrepo.osbuild.org/v2/mirror/public/f39/f39-x86_64-fedora-20231109/Packages/k/kpartx-0.9.5-2.fc39.x86_64.rpm\n",
Progress: &osbuild.Progress{
Done: 0,
Total: 4,
Expand All @@ -39,7 +39,7 @@ func TestScannerSimple(t *testing.T) {
st, err = scanner.Status()
assert.NoError(t, err)
assert.Equal(t, &osbuild.Status{
Trace: "source/org.osbuild.curl (org.osbuild.curl): Downloaded https://rpmrepo.osbuild.org/v2/mirror/public/f39/f39-x86_64-fedora-20231109/Packages/l/langpacks-fonts-en-4.0-9.fc39.noarch.rpm",
Trace: "source/org.osbuild.curl (org.osbuild.curl): Downloaded https://rpmrepo.osbuild.org/v2/mirror/public/f39/f39-x86_64-fedora-20231109/Packages/l/langpacks-fonts-en-4.0-9.fc39.noarch.rpm\n",
Progress: &osbuild.Progress{
Done: 0,
Total: 4,
Expand Down

0 comments on commit ad627d1

Please sign in to comment.