Skip to content

Commit 4ce0ecf

Browse files
committed
widget.py: Avoid extra empty lines when message-lines or error-lines is 0
With message-lines set to 0, the detail of a message is truncated away entirely, but LogLine still prints an empty line, a line with only the indentation and another empty line after the message. Likewise, a failure message in verbose mode with error-lines set to 0 skips the log tail, but is still followed by two empty lines instead of the usual one. Only print the message detail when some of it is left, and only add the newline that introduces the failure details when they are printed. Failure messages keep the single empty line that separates them from the next message, and from the next entry in the failure summary. Fixes #2145
1 parent 3f4c304 commit 4ce0ecf

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

‎src/buildstream/_frontend/widget.py‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -782,29 +782,31 @@ def _render(self, message):
782782
else:
783783
lines[n_lines - 1] = lines[n_lines - 1].rstrip("\n")
784784

785-
detail = self._indent + self._indent.join(lines)
785+
# Nothing is left to print when message-lines is 0
786+
if lines:
787+
detail = self._indent + self._indent.join(lines)
786788

787-
text += "\n"
788-
if message.message_type in ERROR_MESSAGES:
789-
text += self._err_profile.fmt(detail, bold=True)
790-
else:
791-
text += self._detail_profile.fmt(detail)
789+
text += "\n"
790+
if message.message_type in ERROR_MESSAGES:
791+
text += self._err_profile.fmt(detail, bold=True)
792+
else:
793+
text += self._detail_profile.fmt(detail)
792794

793-
if abbrev:
794-
text += self._indent + self.content_profile.fmt(
795-
"Message contains {} additional lines".format(n_lines - self._message_lines), dim=True
796-
)
797-
text += "\n"
795+
if abbrev:
796+
text += self._indent + self.content_profile.fmt(
797+
"Message contains {} additional lines".format(n_lines - self._message_lines), dim=True
798+
)
799+
text += "\n"
798800

799-
extra_nl = True
801+
extra_nl = True
800802

801803
if message.scheduler and message.message_type == MessageType.FAIL:
802-
text += "\n"
803-
804804
if self.context is not None and not self.context.log_verbose:
805+
text += "\n"
805806
text += self._indent + self._err_profile.fmt("Log file: ")
806807
text += self._indent + self._logfile_widget.render(message) + "\n"
807808
elif self._log_lines > 0:
809+
text += "\n"
808810
text += (
809811
self._indent
810812
+ self._err_profile.fmt("Printing the last {} lines from log file:".format(self._log_lines))

0 commit comments

Comments
 (0)