Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

argparse crash in format_help for hidden commands #9150

Open
sg2342 opened this issue Dec 6, 2024 · 0 comments · May be fixed by #9151
Open

argparse crash in format_help for hidden commands #9150

sg2342 opened this issue Dec 6, 2024 · 0 comments · May be fixed by #9151
Assignees
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM

Comments

@sg2342
Copy link
Contributor

sg2342 commented Dec 6, 2024

Describe the bug

since 1aa91e7 argparse:format_help/1 will crash when its Options contain a 'hidden' command.

invocation of argparse:run/3 with a 'hidden' command in Args will -- when argparse:parse/3 fails -- print the error and then an exception message (instead of the related help).

To Reproduce

Erlang/OTP 27 [erts-15.1.2] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns] [dtrace] [sharing-preserving]

Eshell V15.1.2 (press Ctrl+G to abort, type help(). for help)
1> Cmd = #{commands => #{"foo" => #{help => hidden, arguments => [#{name => x, help => "the X", type => integer}]}}}.
#{commands =>
      #{"foo" =>
            #{arguments => [#{name => x,type => integer,help => "the X"}],
              help => hidden}}}
2> argparse:run(["foo", "NaN"], Cmd, #{}).
error: erl foo: invalid argument for x: NaN is not an integer
** exception error: bad generator hidden
     in function  argparse:'-format_help/2-lc$^1/1-1-'/3 (argparse.erl, line 1652)
     in call from argparse:format_help/2 (argparse.erl, line 1652)
     in call from argparse:run/3 (argparse.erl, line 782)
3> 

Expected behavior

Erlang/OTP 26 [erts-14.2.5.4] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns] [dtrace] [sharing-preserving]

Eshell V14.2.5.4 (press Ctrl+G to abort, type help(). for help)
1> Cmd = #{commands => #{"foo" => #{help => hidden, arguments => [#{name => x, help => "the X", type => integer}]}}}.
#{commands =>
      #{"foo" =>
            #{arguments => [#{name => x,type => integer,help => "the X"}],
              help => hidden}}}
2> argparse:run(["foo", "NaN"], Cmd, #{}).
error: erl foo: invalid argument for x: NaN is not an integer
Usage:
  erl foo <x>

Arguments:
  x the X (int)

Affected versions

OTP-27.1.3
OTP-27.1.2
OTP-27.1.1
OTP-27.1

@sg2342 sg2342 added the bug Issue is reported as a bug label Dec 6, 2024
sg2342 added a commit to sg2342/otp that referenced this issue Dec 6, 2024
@rickard-green rickard-green added the team:VM Assigned to OTP team VM label Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants