Skip to content

Commit

Permalink
Detect invalid default flag value in flag:call
Browse files Browse the repository at this point in the history
  • Loading branch information
krader1961 committed Jan 16, 2024
1 parent 76e2d3c commit a8ff1fd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/mods/flag/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func call(fm *eval.Frame, fn *eval.Closure, argsVal vals.List) error {
fs := newFlagSet("")
for i, name := range fn.OptNames {
value := fn.OptDefaults[i]
addFlag(fs, name, value, "")
if err := addFlag(fs, name, value, ""); err != nil {
return err
}
}
err = fs.Parse(args)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/mods/flag/flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func TestCall(t *testing.T) {
// Bad argument list
That("flag:call { } [(num 0)]").
Throws(ErrorWithMessage("wrong type: need string, got number")),
// Validate invalid default flag value raises an exception.
That("flag:call {|&f=$nil| } [-f 1]").
Throws(errs.BadValue{What: "flag default value",
Valid: "boolean, number, string or list", Actual: "$nil"}),
// More flag parsing logic is covered in TestParse
)

Expand Down

0 comments on commit a8ff1fd

Please sign in to comment.