Skip to content

Commit 5de4918

Browse files
authored
Merge branch 'v3' into dependabot/go_modules/golang.org/x/tools-0.20.0
2 parents 5f23dee + b1406f1 commit 5de4918

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

eval/eval.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package eval
22

33
import (
44
"fmt"
5-
"path/filepath"
65
"reflect"
76
"runtime"
87
"strings"
8+
"unicode"
99
)
1010

1111
// RunDSL iterates through the root expressions and calls WalkSets on each to
@@ -116,8 +116,7 @@ func ReportError(fm string, vals ...any) {
116116
// IncompatibleDSL should be called by DSL functions when they are invoked in an
117117
// incorrect context (e.g. "Params" in "Service").
118118
func IncompatibleDSL() {
119-
elems := strings.Split(caller(), ".")
120-
ReportError("invalid use of %s", elems[len(elems)-1])
119+
ReportError("invalid use of %s", caller())
121120
}
122121

123122
// InvalidArgError records an invalid argument error. It is used by DSL
@@ -235,13 +234,20 @@ func finalizeSet(set ExpressionSet) {
235234

236235
// caller returns the name of calling function.
237236
func caller() string {
238-
pc, file, _, ok := runtime.Caller(2)
239-
if ok && filepath.Base(file) == "current.go" {
240-
pc, _, _, ok = runtime.Caller(3)
241-
}
242-
if !ok {
243-
return "<unknown>"
237+
for skip := 2; skip <= 3; skip++ {
238+
pc, _, _, ok := runtime.Caller(skip)
239+
if !ok {
240+
break
241+
}
242+
name := runtime.FuncForPC(pc).Name()
243+
elems := strings.Split(name, ".")
244+
caller := elems[len(elems)-1]
245+
for _, first := range caller {
246+
if unicode.IsUpper(first) {
247+
return caller
248+
}
249+
break
250+
}
244251
}
245-
246-
return runtime.FuncForPC(pc).Name()
252+
return "<unknown>"
247253
}

expr/http_endpoint_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package expr_test
22

33
import (
4+
"strings"
45
"testing"
56

67
"goa.design/goa/v3/eval"
@@ -15,18 +16,19 @@ func TestHTTPRouteValidation(t *testing.T) {
1516
Error string
1617
}{
1718
{"valid", testdata.ValidRouteDSL, ""},
18-
{"invalid", testdata.DuplicateWCRouteDSL, `route POST "/{id}" of service "InvalidRoute" HTTP endpoint "Method": Wildcard "id" appears multiple times in full path "/{id}/{id}"`},
19+
{"duplicate-wc-route", testdata.DuplicateWCRouteDSL, `route POST "/{id}" of service "DuplicateWCRoute" HTTP endpoint "Method": Wildcard "id" appears multiple times in full path "/{id}/{id}"`},
1920
{"disallow-response-body", testdata.DisallowResponseBodyHeadDSL, `route HEAD "/" of service "DisallowResponseBody" HTTP endpoint "Method": HTTP status 200: Response body defined for HEAD method which does not allow response body.
2021
route HEAD "/" of service "DisallowResponseBody" HTTP endpoint "Method": HTTP status 404: Response body defined for HEAD method which does not allow response body.`,
2122
},
23+
{"invalid", testdata.InvalidRouteDSL, "invalid use of POST in service \"InvalidRoute\""},
2224
}
2325
for _, c := range cases {
2426
t.Run(c.Name, func(t *testing.T) {
2527
if c.Error == "" {
2628
expr.RunDSL(t, c.DSL)
2729
} else {
2830
err := expr.RunInvalidDSL(t, c.DSL)
29-
if err.Error() != c.Error {
31+
if !strings.HasSuffix(err.Error(), c.Error) {
3032
t.Errorf("got error %q\nexpected %q", err.Error(), c.Error)
3133
}
3234
}

expr/testdata/endpoint_dsls.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var ValidRouteDSL = func() {
2222
}
2323

2424
var DuplicateWCRouteDSL = func() {
25-
Service("InvalidRoute", func() {
25+
Service("DuplicateWCRoute", func() {
2626
HTTP(func() {
2727
Path("/{id}")
2828
})
@@ -52,6 +52,14 @@ var DisallowResponseBodyHeadDSL = func() {
5252
})
5353
}
5454

55+
var InvalidRouteDSL = func() {
56+
Service("InvalidRoute", func() {
57+
HTTP(func() {
58+
POST("/{id}")
59+
})
60+
})
61+
}
62+
5563
var EndpointWithParentDSL = func() {
5664
Service("Parent", func() {
5765
Method("show", func() {

0 commit comments

Comments
 (0)