Skip to content

base: fix pty view because crlf are lost in .lines() - #8332

Merged
LeFrosch merged 1 commit into
bazelbuild:masterfrom
ujohnny:enovozhilov/fix-pty
May 19, 2026
Merged

base: fix pty view because crlf are lost in .lines()#8332
LeFrosch merged 1 commit into
bazelbuild:masterfrom
ujohnny:enovozhilov/fix-pty

Conversation

@ujohnny

@ujohnny ujohnny commented May 17, 2026

Copy link
Copy Markdown
Collaborator

when we have pty view we have to preserve all control chars to make it work propely

when we have pty view we have to preserve all control
chars to make it work propely
@ujohnny
ujohnny requested review from LeFrosch and mai93 as code owners May 17, 2026 20:29
@github-actions github-actions Bot added product: CLion CLion plugin product: IntelliJ IntelliJ plugin product: GoLand GoLand plugin awaiting-review Awaiting review from Bazel team on PRs labels May 17, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates BazelExecServiceImpl.kt to handle stderr output using raw character buffers when a PTY is active, ensuring control characters are preserved. The reviewer recommended applying a similar approach to stdout to prevent output mangling and suggested refactoring the stderr logic to reduce code duplication by moving the buffered reader initialization outside the conditional check.

reader.lines().forEach { line ->
ctx.println(line)
LOG.debug("BAZEL ERR: $line")
if (usePty) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While this change correctly handles stderr for PTY output by preserving control characters, the stdout stream (handled at line 145) is still being passed to a LineProcessingOutputStream in the build() method (line 252). This will cause stdout to still lose control characters and CRLF, as LineProcessingOutputStream and the subsequent ctx.println call will mangle the output by trimming and normalizing line endings. Consider applying a similar raw-output approach to stdout when usePty is true to ensure the PTY view works correctly for all output streams.

References
  1. A simpler, custom implementation can be preferable to a standard one if it avoids unwanted complexity for the specific use case.

Comment on lines +149 to 167
if (usePty) {
process.errorStream.bufferedReader().use { reader ->
val buf = CharArray(DEFAULT_BUFFER_SIZE)
while (true) {
val n = reader.read(buf)
if (n < 0) break
val text = String(buf, 0, n)
ctx.output(PrintOutput.process(text))
// no log.debug because it's pty
}
}
} else {
process.errorStream.bufferedReader().use { reader ->
reader.lines().forEach { line ->
ctx.println(line)
LOG.debug("BAZEL ERR: $line")
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for opening the bufferedReader on process.errorStream is duplicated in both branches of the if (usePty) check. You can simplify the code by moving the use block outside the conditional to improve maintainability.

          process.errorStream.bufferedReader().use { reader ->
            if (usePty) {
              val buf = CharArray(DEFAULT_BUFFER_SIZE)
              while (true) {
                val n = reader.read(buf)
                if (n < 0) break
                ctx.output(PrintOutput.process(String(buf, 0, n)))
                // no log.debug because it's pty
              }
            } else {
              reader.lines().forEach { line ->
                ctx.println(line)
                LOG.debug("BAZEL ERR: $line")
              }
            }
          }

@LeFrosch
LeFrosch merged commit 9c86904 into bazelbuild:master May 19, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from Untriaged to Done in Bazel IntelliJ Plugin May 19, 2026
@github-actions github-actions Bot removed the awaiting-review Awaiting review from Bazel team on PRs label May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: CLion CLion plugin product: GoLand GoLand plugin product: IntelliJ IntelliJ plugin

Projects

Development

Successfully merging this pull request may close these issues.

2 participants