Skip to content

Commit 18d5007

Browse files
authored
Use eval.InvalidArgError() to dsl.Payload() (#3689)
1 parent c7b7a0f commit 18d5007

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

dsl/payload.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,13 @@ func methodDSL(m *expr.MethodExpr, suffix string, p any, args ...any) *expr.Attr
176176
case expr.DataType:
177177
att = &expr.AttributeExpr{Type: actual}
178178
default:
179-
eval.ReportError("invalid %s argument, must be a type or a function", suffix)
179+
eval.InvalidArgError("type or function", p)
180180
return nil
181181
}
182182
if len(args) >= 1 {
183183
if f, ok := args[len(args)-1].(func()); ok {
184184
if fn != nil {
185-
eval.ReportError("invalid arguments in %s call, must be (type), (func), (type, func), (type, desc) or (type, desc, func)", suffix)
185+
eval.InvalidArgError("(type), (func), (type, func), (type, desc) or (type, desc, func)", f)
186186
}
187187
fn = f
188188
}

eval/eval_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func TestInvalidArgError(t *testing.T) {
3030
"OneOf (function)": {func() { Type("name", func() { OneOf("name", "description", 1) }) }, "cannot use 1 (type int) as type function"},
3131
"OneOf (string)": {func() { Type("name", func() { OneOf("name", 1, func() {}) }) }, "cannot use 1 (type int) as type string"},
3232
"Param": {func() { API("name", func() { HTTP(func() { Params(1) }) }) }, "cannot use 1 (type int) as type function"},
33+
"Payload": {func() { Service("s", func() { Method("m", func() { Payload(1) }) }) }, "cannot use 1 (type int) as type type or function"},
34+
"Payload (args)": {func() { Service("s", func() { Method("m", func() { Payload(func() {}, func() {}) }) }) }, "(type func()) as type (type), (func), (type, func), (type, desc) or (type, desc, func)"},
3335
"Response": {func() { Service("s", func() { HTTP(func() { Response(1) }) }) }, "cannot use 1 (type int) as type name of error"},
3436
"ResultType": {func() { ResultType("identifier", 1) }, "cannot use 1 (type int) as type function or string"},
3537
"Security": {func() { Security(1) }, "cannot use 1 (type int) as type security scheme or security scheme name"},

0 commit comments

Comments
 (0)