Skip to content

Keep the exit status when the CLI cannot print an error to stderr - #16080

Merged
josevalim merged 2 commits into
elixir-lang:mainfrom
lessthanseventy:cli-print-error-dead-stderr
Nov 8, 2026
Merged

josevalim merged 2 commits into
elixir-lang:mainfrom
lessthanseventy:cli-print-error-dead-stderr

Conversation

@lessthanseventy

Copy link
Copy Markdown
Contributor

Closes #16079.

When a script raises and stderr cannot be written to (a closed descriptor, or a pipe whose reader has exited), Kernel.CLI.print_error/3 raised from inside the catch in exec_fun/2, the :DOWN branch tried to print again, and the exception escaped Kernel.CLI.run/1 into init:start_it: "Runtime terminating during boot" and an erl_crash.dump in the cwd, instead of exit status 1.

print_error/3 now treats the stderr write as best-effort. The test runs elixir -e "raise ArgumentError" with stderr a dead pipe and asserts status 1 and no crash dump; it fails before this change and passes after. make format is clean and make test_stdlib passes on OTP 29.

When a script raises and stderr cannot be written to (a closed descriptor,
or a pipe whose reader has exited), Kernel.CLI.print_error/3 raised from
inside the catch in exec_fun/2, the :DOWN branch tried to print again, and
the exception escaped Kernel.CLI.run/1 into init:start_it: the VM reported
"Runtime terminating during boot" and wrote an erl_crash.dump into the cwd
instead of exiting with status 1.

print_error/3 now treats the stderr write as best-effort.

Closes elixir-lang#16079

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018wugBUzZrvZNchWxmRqJgH
Comment thread lib/elixir/lib/kernel/cli.ex Resolved
@josevalim
josevalim merged commit a17c2c4 into elixir-lang:main Nov 8, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Kernel.CLI crashes the VM (erl_crash.dump) when a script raises and stderr is unwritable

2 participants