Skip to content

fix: discard subprocess stdout/stderr to prevent LSP stream corruption#96

Open
diofeher wants to merge 1 commit intomainfrom
fix/discard-subprocess-stdout
Open

fix: discard subprocess stdout/stderr to prevent LSP stream corruption#96
diofeher wants to merge 1 commit intomainfrom
fix/discard-subprocess-stdout

Conversation

@diofeher
Copy link
Copy Markdown
Contributor

@diofeher diofeher commented Apr 7, 2026

Summary

  • TerragruntOptions.Writer defaults to os.Stdout, so run_cmd subprocess output (e.g. ssh-keygen fingerprints) leaks into the LSP protocol stream
  • This corrupts the Content-Length headers, causing the language server client to crash with: Header must provide a Content-Length property
  • Fix: set opts.Writer and opts.ErrWriter to io.Discard so subprocess output is silently discarded

Fixes #88

The main root cause of the issue was actually fixed by #92, but when trying the configuration from the issue above, it generated a new error on the extension:

❯ Client Terragrunt Language Server: connection to server is erroring. Header
must provide a Content-Length property. {"256
md5":"b3:37:06:8d:56:9b:79:14:07:2b:ab:28:20:92:21:48 ****@gruntwork.io
(ED25519)\n256 MD5:b3:37:06:8d:56:9b:79:14:07:2b:ab:28:20:92:21:48
****@gruntwork.io (ED25519)\nContent-Length: 190"} Shutting down server.

Test plan

  • go build ./... compiles cleanly
  • go test ./... all tests pass
  • Open a .hcl file containing run_cmd("ssh-keygen", ...) in VSCode and verify the language server no longer crashes

Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
@diofeher diofeher requested a review from yhakbar as a code owner April 7, 2026 22:21
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 7, 2026

Walkthrough

The ParseTerragruntBuffer function in internal/tg/parse.go now explicitly discards both standard output and error output during Terragrunt parsing by assigning io.Discard to the writer options, with the io import added accordingly.

Changes

Cohort / File(s) Summary
Output Handling Configuration
internal/tg/parse.go
Sets Terragrunt parser to discard stdout and stderr by configuring opts.Writer and opts.ErrWriter to io.Discard, plus adds the corresponding import.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🔇 A whisper becomes silence,
Output cast to the void,
Clean logs, cleaner parsing—
Noise? Discarded with style. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main change: discarding subprocess output to prevent LSP stream corruption, which directly addresses the core issue fixed in this PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/discard-subprocess-stdout

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overly aggressive pattern matching on valid commands that include | and ()

1 participant