Thanks to visit codestin.com
Credit goes to github.com

Skip to content

argparse crash in format_help for hidden commands #9150

@sg2342

Description

@sg2342

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

Metadata

Metadata

Assignees

Labels

bugIssue is reported as a bugteam:VMAssigned to OTP team VM

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions