Skip to content

Commit

Permalink
Use eval.InvalidArgError() to dsl.OneOf()
Browse files Browse the repository at this point in the history
  • Loading branch information
tchssk committed Dec 20, 2024
1 parent d507a89 commit 40ab6dd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions dsl/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,13 @@ func OneOf(name string, args ...any) {
}
fn, ok := args[len(args)-1].(func())
if !ok {
eval.ReportError("OneOf: last argument must be a function")
eval.InvalidArgError("function", args[len(args)-1])
}
var desc string
if len(args) > 1 {
desc, ok = args[0].(string)
if !ok {
eval.ReportError("OneOf: description must be a string")
eval.InvalidArgError("string", args[0])
}
}
Attribute(name, &expr.Union{TypeName: name}, desc, fn)
Expand Down
2 changes: 2 additions & 0 deletions eval/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func TestInvalidArgError(t *testing.T) {
"ErrorName (int)": {func() { Type("name", func() { ErrorName(1, 2) }) }, "cannot use 2 (type int) as type name"},
"Example": {func() { Example(1, 2) }, "cannot use 1 (type int) as type summary (string)"},
"Headers": {func() { Headers(1) }, "cannot use 1 (type int) as type function"},
"OneOf (function)": {func() { Type("name", func() { OneOf("name", "description", 1) }) }, "cannot use 1 (type int) as type function"},
"OneOf (string)": {func() { Type("name", func() { OneOf("name", 1, func() {}) }) }, "cannot use 1 (type int) as type string"},
"Param": {func() { API("name", func() { HTTP(func() { Params(1) }) }) }, "cannot use 1 (type int) as type function"},
"Response": {func() { Service("s", func() { HTTP(func() { Response(1) }) }) }, "cannot use 1 (type int) as type name of error"},
"ResultType": {func() { ResultType("identifier", 1) }, "cannot use 1 (type int) as type function or string"},
Expand Down

0 comments on commit 40ab6dd

Please sign in to comment.