Skip to content

Fix order of calling w.Close in Wrap - #689

Open
neomantra wants to merge 1 commit into
charmbracelet:mainfrom
neomantra:fix-wrap-defer
Open

Fix order of calling w.Close in Wrap#689
neomantra wants to merge 1 commit into
charmbracelet:mainfrom
neomantra:fix-wrap-defer

Conversation

@neomantra

Copy link
Copy Markdown

I surfaced this testing Crush; chains with a Glamour issue. LLM-assisted, but I read and understood the patch.


Close BEFORE reading buf so the trailing ResetStyle / ResetHyperlink
that the WrapWriter emits on close is included in the returned string.

Using defer w.Close() here would write the closing resets to buf after buf.String() snapshots it, dropping them from the return value and leaving callers with output that ends in a dangling SGR/OSC8 — which in turn trips a use-after-close panic in glamour's IndentWriter.Close write-cascade.

  • [X ] I have read CONTRIBUTING.md.
  • I have created a discussion that was approved by a maintainer (for new features).

…link`

the `WrapWriter` emits on close is included in the returned string.

Using `defer w.Close()` here would write the closing resets to buf
*after* `buf.String()` snapshots it, dropping them from the return
value and leaving callers with output that ends in a dangling
SGR/OSC8 — which in turn trips a use-after-close panic in
glamour's `IndentWriter.Close` write-cascade.

Signed-off-by: Evan Wies <evan@neomantra.net>
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.

1 participant