Repository navigation
fix(parser): gate parse-error ANSI on IO.ANSI.enabled?/0 - #385
Merged
Merged
Conversation
Lua.Parser.Error.format/2, format_context/2, and format_multiple/2
emitted IO.ANSI escapes unconditionally, bypassing the IO.ANSI.enabled?/0
gating the runtime VM path already respects. Those strings flow through
parse_chunk/1 into %Lua.CompilerException{errors: [...]}, so escape codes
leaked into the returned tuple regardless of environment.
Add a color/2 helper mirroring Lua.VM.ErrorFormatter.color/2 and route
every colorized fragment through it. Colored on a real TTY, plain text
otherwise.
Closes #382
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #382.
Lua.parse_chunk("asdf")returned error strings full of raw ANSI escape codes (\e[31m…) even when ANSI is disabled.Lua.Parser.Error.format/2emittedIO.ANSIescapes unconditionally, bypassing theIO.ANSI.enabled?/0gating that the runtime VM path (Lua.VM.ErrorFormatter, #304) already respects. Those strings flow throughparse_chunk/1into%Lua.CompilerException{errors: [...]}, so the escapes leaked into the returned tuple regardless of environment.(The contributor's follow-up ask on the issue — return a
%Lua.CompilerException{}rather than a bare string list — was already delivered by #380.)Fix
lib/lua/parser/error.ex— add a privatecolor/2helper mirroringLua.VM.ErrorFormatter.color/2, and route every colorized fragment informat/2,format_context/2, andformat_multiple/2through it. No message text or public API changes — only the presence of escape codes, and only when ANSI is disabled.Behavior
Tests
test/lua/parser/error_test.exs— drops the now-invalid "ANSI always present" assertions; adds a gating regression (ANSI off → no\e[).test/lua/parser/error_ansi_test.exs(new,async: false) — the ANSI-on assertions, isolated into a sync module so toggling the globalansi_enabledcan't race concurrent async tests asserting plain text.test/lua_test.exs— end-to-end guard thatparse_chunk/1's%Lua.CompilerException{}errors carry no escapes when color is disabled.Full suite: 2580 passed, 7 skipped, 30 excluded.
Note on #384
#384 reports the same class of bug at a deeper level: exceptions memoize their gated render at construction time, so a render frozen in a TTY keeps its escapes into non-TTY sinks. This PR adds the parser gate that a construction-time fix depends on, but the full deferral fix is tracked separately in #384.