Skip to content

Commit 1287e2f

Browse files
committed
fix(epipe): catch EPIPE in escript mode too
The Burrito wrapper fix handles EPIPE for Burrito binaries, but escripts don't go through the wrapper. Add a rescue in CLI.run/1 that catches the ErlangError (:terminated) from the dead standard_io group leader and halts with flush:false to exit cleanly without printing the 'Writer crashed (epipe)' stack trace.
1 parent 1f09f9a commit 1287e2f

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

lib/ado_cli/cli.ex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@ defmodule AdoCli.CLI do
167167
apply_global_opts(parsed.options)
168168

169169
parsed.execute.()
170+
rescue
171+
_ in ErlangError ->
172+
# EPIPE: standard_io group leader is dead (pipe closed by head/etc).
173+
# Halt directly with flush:false to skip the IO flush that hangs
174+
# in Burrito binaries and crashes with ugly stack traces in escripts.
175+
:erlang.halt(0, [{:flush, false}])
176+
catch
177+
_, _ ->
178+
:erlang.halt(1, [{:flush, false}])
170179
end
171180

172181
# String options that should consume all subsequent non-flag tokens.

0 commit comments

Comments
 (0)