Skip to content

lfe -eval Crash on OTP 28: user_drv {badkey, input} #517

Closed

Description

@oubiwann

Environment

Component Version
OTP 28 (BEAM emulator 16.1.1)
LFE 2.2.1 (commit 99ea89c)
Platform macOS Darwin 24.6.0, aarch64

Minimal Reproduction

# Set up LFE on PATH (adjust to your checkout)
export LFE_DIR=/path/to/lfe
export ERL_LIBS="$LFE_DIR"
export PATH="$LFE_DIR/bin:$PATH"

# This crashes:
lfe -eval '(io:format "hello~n" ()) (halt)'

The lfe shell script detects that -eval arguments are present (line 101),
appends -noshell to the erl flags, and adds -user lfe_init -extra ... so
that LFE's own init module handles startup.

The crash output:

=ERROR REPORT====
** State machine user_drv terminating
** When server state  = {undefined,undefined}
** Reason for termination = error:{badkey,input}
** Callback modules = [user_drv]
** Callback mode = state_functions
** Stacktrace =
**  [{erlang,map_get,
             [input,#{initial_shell => noshell}],
             [{error_info,#{module => erl_erts_errors}}]},
     {user_drv,init,1,[{file,"user_drv.erl"},{line,187}]},
     ...

Interactive lfe (no -eval) works — only the scripting/eval path crashes.

Diagnostic

The call chain

  1. bin/lfe (shell script, line 101-103): When arguments remain after flag
    processing, appends -noshell to the erl invocation.

  2. bin/lfe (line 105): Always appends -user lfe_init -extra ..., making
    lfe_init:start/0 the user-process entry point.

  3. lfe_init:start/0 (lfe_init.erl:56-73): Calls collect_args/1 to
    split arguments into eval-strings and script-file. When evals or a script are
    present, it enters the noshell branch.

  4. lfe_init.erl:66-68 (the crash site):

    if OTPRelease >= "26" ->
        user_drv:start(#{initial_shell => noshell});

    This passes a map with only the initial_shell key.

  5. user_drv:init/1 (user_drv.erl:179-217, OTP 28): The init callback
    computes StartShell = maps:get(initial_shell, Args, undefined) =/= noshell
    — which is false for the noshell case. This selects the true -> branch at
    line 198:

    true ->
        TTYState = prim_tty:init(
                     #{ input => maps:get(input, Args), output => raw }),
        ...
        {ok, init, {Args, #state{ terminal_mode = maps:get(input, Args), ... }}, ...}

    maps:get(input, Args) has no default. Since Args is
    #{initial_shell => noshell}, the call raises {badkey, input}.

Root cause

OTP 28 (via PR #8962) restructured
-noshell mode into two sub-modes — raw (bypass line editing) and cooked
(the old default behaviour). This changed the arguments() type from:

%% OTP 26–27
-type arguments() :: #{ initial_shell => ..., input => boolean() }.

to:

%% OTP 28
-type arguments() :: #{ initial_shell => ..., input => cooked | raw | disabled }.

In OTP 27, the noshell code path used maps:get(input, Args, true) — a default
of true. In OTP 28, the refactoring dropped that default, making input a
required key in the noshell path, despite the type spec declaring it
optional (Erlang map types use key => value for optional keys).

There are four bare maps:get(input, Args) calls in OTP 28's user_drv.erl
(lines 200, 202, 401, 429), all without defaults, all reachable when
initial_shell => noshell.

OTP version boundary

OTP input key Default LFE -eval works?
≤ 25 not in type N/A (used user:start()) yes
26–27 boolean() true yes
28 cooked | raw | disabled none no

Workaround

Until LFE is patched, use erl -noshell with LFE on the code path instead of
lfe -eval:

export LFE_DIR=/path/to/lfe

# Instead of: lfe -eval '(io:format "hello~n" ()) (halt)'
# Use:
erl -noshell -pa "$LFE_DIR/ebin" -eval '
  lfe_shell:run_strings(["(io:format \"hello~n\" ()) (halt)"]),
  halt().
'

# For compilation:
erl -noshell -pa "$LFE_DIR/ebin" -eval '
  lfe_comp:file("mymod.lfe", [verbose, report, {outdir, "."}]),
  halt().
'

This bypasses lfe_init and user_drv entirely.

Activity

  1. changed the title [-]user_drv issue (placeholder)[/-] [+]`lfe -eval` Crash on OTP 28: `user_drv` `{badkey, input}`[/+] on Jun 7, 2026
  2. added a commit that references this issue on Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions