Skip to content

Commit 595b090

Browse files
[BEAM-3878] Improve error reporting in calls.go (apache#15221)
* [BEAM-3878] Improved error reporting in calls.go * [BEAM-3878] add steps to edit .tmpl file in BUILD.md Co-authored-by: Holden Karau <holden@pigscanfly.ca>
1 parent 4193828 commit 595b090

File tree

4 files changed

+53
-36
lines changed

4 files changed

+53
-36
lines changed

sdks/go/BUILD.md

+10
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,13 @@ Developers must invoke Go for cross-compilation manually, if desired.
6464

6565
If you make changes to .proto files, you will need to rebuild the generated code.
6666
Consult `pkg/beam/model/PROTOBUF.md`.
67+
68+
If you make changes to .tmpl files, then add the specialize tool to your path.
69+
You can install specialize using:
70+
```
71+
go get github.com/apache/beam/sdks/go/cmd/specialize
72+
```
73+
Add it to your path:
74+
```
75+
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
76+
```

sdks/go/pkg/beam/core/util/reflectx/call.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import (
1919
"reflect"
2020
"sync"
2121

22-
"github.com/apache/beam/sdks/go/pkg/beam/internal/errors"
2322
"runtime/debug"
23+
24+
"github.com/apache/beam/sdks/go/pkg/beam/internal/errors"
2425
)
2526

2627
//go:generate specialize --input=calls.tmpl

sdks/go/pkg/beam/core/util/reflectx/calls.go

+36-33
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717

1818
package reflectx
1919

20-
import "reflect"
20+
import (
21+
"fmt"
22+
"reflect"
23+
)
2124

2225
// Generated arity-specialized Func implementations to avoid runtime temporary
2326
// slices. Code that knows the arity can potentially avoid that overhead in
@@ -57,7 +60,7 @@ func (c *shimFunc0x0) Call0x0() {
5760

5861
func ToFunc0x0(c Func) Func0x0 {
5962
if c.Type().NumIn() != 0 || c.Type().NumOut() != 0 {
60-
panic("incompatible func type")
63+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 0 inputs and 0 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
6164
}
6265
if sc, ok := c.(Func0x0); ok {
6366
return sc
@@ -98,7 +101,7 @@ func (c *shimFunc0x1) Call0x1() interface{} {
98101

99102
func ToFunc0x1(c Func) Func0x1 {
100103
if c.Type().NumIn() != 0 || c.Type().NumOut() != 1 {
101-
panic("incompatible func type")
104+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 0 inputs and 1 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
102105
}
103106
if sc, ok := c.(Func0x1); ok {
104107
return sc
@@ -139,7 +142,7 @@ func (c *shimFunc0x2) Call0x2() (interface{}, interface{}) {
139142

140143
func ToFunc0x2(c Func) Func0x2 {
141144
if c.Type().NumIn() != 0 || c.Type().NumOut() != 2 {
142-
panic("incompatible func type")
145+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 0 inputs and 2 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
143146
}
144147
if sc, ok := c.(Func0x2); ok {
145148
return sc
@@ -180,7 +183,7 @@ func (c *shimFunc0x3) Call0x3() (interface{}, interface{}, interface{}) {
180183

181184
func ToFunc0x3(c Func) Func0x3 {
182185
if c.Type().NumIn() != 0 || c.Type().NumOut() != 3 {
183-
panic("incompatible func type")
186+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 0 inputs and 3 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
184187
}
185188
if sc, ok := c.(Func0x3); ok {
186189
return sc
@@ -221,7 +224,7 @@ func (c *shimFunc1x0) Call1x0(arg0 interface{}) {
221224

222225
func ToFunc1x0(c Func) Func1x0 {
223226
if c.Type().NumIn() != 1 || c.Type().NumOut() != 0 {
224-
panic("incompatible func type")
227+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 1 inputs and 0 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
225228
}
226229
if sc, ok := c.(Func1x0); ok {
227230
return sc
@@ -262,7 +265,7 @@ func (c *shimFunc1x1) Call1x1(arg0 interface{}) interface{} {
262265

263266
func ToFunc1x1(c Func) Func1x1 {
264267
if c.Type().NumIn() != 1 || c.Type().NumOut() != 1 {
265-
panic("incompatible func type")
268+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 1 inputs and 1 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
266269
}
267270
if sc, ok := c.(Func1x1); ok {
268271
return sc
@@ -303,7 +306,7 @@ func (c *shimFunc1x2) Call1x2(arg0 interface{}) (interface{}, interface{}) {
303306

304307
func ToFunc1x2(c Func) Func1x2 {
305308
if c.Type().NumIn() != 1 || c.Type().NumOut() != 2 {
306-
panic("incompatible func type")
309+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 1 inputs and 2 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
307310
}
308311
if sc, ok := c.(Func1x2); ok {
309312
return sc
@@ -344,7 +347,7 @@ func (c *shimFunc1x3) Call1x3(arg0 interface{}) (interface{}, interface{}, inter
344347

345348
func ToFunc1x3(c Func) Func1x3 {
346349
if c.Type().NumIn() != 1 || c.Type().NumOut() != 3 {
347-
panic("incompatible func type")
350+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 1 inputs and 3 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
348351
}
349352
if sc, ok := c.(Func1x3); ok {
350353
return sc
@@ -385,7 +388,7 @@ func (c *shimFunc2x0) Call2x0(arg0, arg1 interface{}) {
385388

386389
func ToFunc2x0(c Func) Func2x0 {
387390
if c.Type().NumIn() != 2 || c.Type().NumOut() != 0 {
388-
panic("incompatible func type")
391+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 2 inputs and 0 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
389392
}
390393
if sc, ok := c.(Func2x0); ok {
391394
return sc
@@ -426,7 +429,7 @@ func (c *shimFunc2x1) Call2x1(arg0, arg1 interface{}) interface{} {
426429

427430
func ToFunc2x1(c Func) Func2x1 {
428431
if c.Type().NumIn() != 2 || c.Type().NumOut() != 1 {
429-
panic("incompatible func type")
432+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 2 inputs and 1 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
430433
}
431434
if sc, ok := c.(Func2x1); ok {
432435
return sc
@@ -467,7 +470,7 @@ func (c *shimFunc2x2) Call2x2(arg0, arg1 interface{}) (interface{}, interface{})
467470

468471
func ToFunc2x2(c Func) Func2x2 {
469472
if c.Type().NumIn() != 2 || c.Type().NumOut() != 2 {
470-
panic("incompatible func type")
473+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 2 inputs and 2 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
471474
}
472475
if sc, ok := c.(Func2x2); ok {
473476
return sc
@@ -508,7 +511,7 @@ func (c *shimFunc2x3) Call2x3(arg0, arg1 interface{}) (interface{}, interface{},
508511

509512
func ToFunc2x3(c Func) Func2x3 {
510513
if c.Type().NumIn() != 2 || c.Type().NumOut() != 3 {
511-
panic("incompatible func type")
514+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 2 inputs and 3 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
512515
}
513516
if sc, ok := c.(Func2x3); ok {
514517
return sc
@@ -549,7 +552,7 @@ func (c *shimFunc3x0) Call3x0(arg0, arg1, arg2 interface{}) {
549552

550553
func ToFunc3x0(c Func) Func3x0 {
551554
if c.Type().NumIn() != 3 || c.Type().NumOut() != 0 {
552-
panic("incompatible func type")
555+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 3 inputs and 0 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
553556
}
554557
if sc, ok := c.(Func3x0); ok {
555558
return sc
@@ -590,7 +593,7 @@ func (c *shimFunc3x1) Call3x1(arg0, arg1, arg2 interface{}) interface{} {
590593

591594
func ToFunc3x1(c Func) Func3x1 {
592595
if c.Type().NumIn() != 3 || c.Type().NumOut() != 1 {
593-
panic("incompatible func type")
596+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 3 inputs and 1 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
594597
}
595598
if sc, ok := c.(Func3x1); ok {
596599
return sc
@@ -631,7 +634,7 @@ func (c *shimFunc3x2) Call3x2(arg0, arg1, arg2 interface{}) (interface{}, interf
631634

632635
func ToFunc3x2(c Func) Func3x2 {
633636
if c.Type().NumIn() != 3 || c.Type().NumOut() != 2 {
634-
panic("incompatible func type")
637+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 3 inputs and 2 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
635638
}
636639
if sc, ok := c.(Func3x2); ok {
637640
return sc
@@ -672,7 +675,7 @@ func (c *shimFunc3x3) Call3x3(arg0, arg1, arg2 interface{}) (interface{}, interf
672675

673676
func ToFunc3x3(c Func) Func3x3 {
674677
if c.Type().NumIn() != 3 || c.Type().NumOut() != 3 {
675-
panic("incompatible func type")
678+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 3 inputs and 3 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
676679
}
677680
if sc, ok := c.(Func3x3); ok {
678681
return sc
@@ -713,7 +716,7 @@ func (c *shimFunc4x0) Call4x0(arg0, arg1, arg2, arg3 interface{}) {
713716

714717
func ToFunc4x0(c Func) Func4x0 {
715718
if c.Type().NumIn() != 4 || c.Type().NumOut() != 0 {
716-
panic("incompatible func type")
719+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 4 inputs and 0 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
717720
}
718721
if sc, ok := c.(Func4x0); ok {
719722
return sc
@@ -754,7 +757,7 @@ func (c *shimFunc4x1) Call4x1(arg0, arg1, arg2, arg3 interface{}) interface{} {
754757

755758
func ToFunc4x1(c Func) Func4x1 {
756759
if c.Type().NumIn() != 4 || c.Type().NumOut() != 1 {
757-
panic("incompatible func type")
760+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 4 inputs and 1 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
758761
}
759762
if sc, ok := c.(Func4x1); ok {
760763
return sc
@@ -795,7 +798,7 @@ func (c *shimFunc4x2) Call4x2(arg0, arg1, arg2, arg3 interface{}) (interface{},
795798

796799
func ToFunc4x2(c Func) Func4x2 {
797800
if c.Type().NumIn() != 4 || c.Type().NumOut() != 2 {
798-
panic("incompatible func type")
801+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 4 inputs and 2 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
799802
}
800803
if sc, ok := c.(Func4x2); ok {
801804
return sc
@@ -836,7 +839,7 @@ func (c *shimFunc4x3) Call4x3(arg0, arg1, arg2, arg3 interface{}) (interface{},
836839

837840
func ToFunc4x3(c Func) Func4x3 {
838841
if c.Type().NumIn() != 4 || c.Type().NumOut() != 3 {
839-
panic("incompatible func type")
842+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 4 inputs and 3 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
840843
}
841844
if sc, ok := c.(Func4x3); ok {
842845
return sc
@@ -877,7 +880,7 @@ func (c *shimFunc5x0) Call5x0(arg0, arg1, arg2, arg3, arg4 interface{}) {
877880

878881
func ToFunc5x0(c Func) Func5x0 {
879882
if c.Type().NumIn() != 5 || c.Type().NumOut() != 0 {
880-
panic("incompatible func type")
883+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 5 inputs and 0 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
881884
}
882885
if sc, ok := c.(Func5x0); ok {
883886
return sc
@@ -918,7 +921,7 @@ func (c *shimFunc5x1) Call5x1(arg0, arg1, arg2, arg3, arg4 interface{}) interfac
918921

919922
func ToFunc5x1(c Func) Func5x1 {
920923
if c.Type().NumIn() != 5 || c.Type().NumOut() != 1 {
921-
panic("incompatible func type")
924+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 5 inputs and 1 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
922925
}
923926
if sc, ok := c.(Func5x1); ok {
924927
return sc
@@ -959,7 +962,7 @@ func (c *shimFunc5x2) Call5x2(arg0, arg1, arg2, arg3, arg4 interface{}) (interfa
959962

960963
func ToFunc5x2(c Func) Func5x2 {
961964
if c.Type().NumIn() != 5 || c.Type().NumOut() != 2 {
962-
panic("incompatible func type")
965+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 5 inputs and 2 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
963966
}
964967
if sc, ok := c.(Func5x2); ok {
965968
return sc
@@ -1000,7 +1003,7 @@ func (c *shimFunc5x3) Call5x3(arg0, arg1, arg2, arg3, arg4 interface{}) (interfa
10001003

10011004
func ToFunc5x3(c Func) Func5x3 {
10021005
if c.Type().NumIn() != 5 || c.Type().NumOut() != 3 {
1003-
panic("incompatible func type")
1006+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 5 inputs and 3 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
10041007
}
10051008
if sc, ok := c.(Func5x3); ok {
10061009
return sc
@@ -1041,7 +1044,7 @@ func (c *shimFunc6x0) Call6x0(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) {
10411044

10421045
func ToFunc6x0(c Func) Func6x0 {
10431046
if c.Type().NumIn() != 6 || c.Type().NumOut() != 0 {
1044-
panic("incompatible func type")
1047+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 6 inputs and 0 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
10451048
}
10461049
if sc, ok := c.(Func6x0); ok {
10471050
return sc
@@ -1082,7 +1085,7 @@ func (c *shimFunc6x1) Call6x1(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) in
10821085

10831086
func ToFunc6x1(c Func) Func6x1 {
10841087
if c.Type().NumIn() != 6 || c.Type().NumOut() != 1 {
1085-
panic("incompatible func type")
1088+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 6 inputs and 1 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
10861089
}
10871090
if sc, ok := c.(Func6x1); ok {
10881091
return sc
@@ -1123,7 +1126,7 @@ func (c *shimFunc6x2) Call6x2(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) (i
11231126

11241127
func ToFunc6x2(c Func) Func6x2 {
11251128
if c.Type().NumIn() != 6 || c.Type().NumOut() != 2 {
1126-
panic("incompatible func type")
1129+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 6 inputs and 2 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
11271130
}
11281131
if sc, ok := c.(Func6x2); ok {
11291132
return sc
@@ -1164,7 +1167,7 @@ func (c *shimFunc6x3) Call6x3(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) (i
11641167

11651168
func ToFunc6x3(c Func) Func6x3 {
11661169
if c.Type().NumIn() != 6 || c.Type().NumOut() != 3 {
1167-
panic("incompatible func type")
1170+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 6 inputs and 3 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
11681171
}
11691172
if sc, ok := c.(Func6x3); ok {
11701173
return sc
@@ -1205,7 +1208,7 @@ func (c *shimFunc7x0) Call7x0(arg0, arg1, arg2, arg3, arg4, arg5, arg6 interface
12051208

12061209
func ToFunc7x0(c Func) Func7x0 {
12071210
if c.Type().NumIn() != 7 || c.Type().NumOut() != 0 {
1208-
panic("incompatible func type")
1211+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 7 inputs and 0 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
12091212
}
12101213
if sc, ok := c.(Func7x0); ok {
12111214
return sc
@@ -1246,7 +1249,7 @@ func (c *shimFunc7x1) Call7x1(arg0, arg1, arg2, arg3, arg4, arg5, arg6 interface
12461249

12471250
func ToFunc7x1(c Func) Func7x1 {
12481251
if c.Type().NumIn() != 7 || c.Type().NumOut() != 1 {
1249-
panic("incompatible func type")
1252+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 7 inputs and 1 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
12501253
}
12511254
if sc, ok := c.(Func7x1); ok {
12521255
return sc
@@ -1287,7 +1290,7 @@ func (c *shimFunc7x2) Call7x2(arg0, arg1, arg2, arg3, arg4, arg5, arg6 interface
12871290

12881291
func ToFunc7x2(c Func) Func7x2 {
12891292
if c.Type().NumIn() != 7 || c.Type().NumOut() != 2 {
1290-
panic("incompatible func type")
1293+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 7 inputs and 2 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
12911294
}
12921295
if sc, ok := c.(Func7x2); ok {
12931296
return sc
@@ -1328,7 +1331,7 @@ func (c *shimFunc7x3) Call7x3(arg0, arg1, arg2, arg3, arg4, arg5, arg6 interface
13281331

13291332
func ToFunc7x3(c Func) Func7x3 {
13301333
if c.Type().NumIn() != 7 || c.Type().NumOut() != 3 {
1331-
panic("incompatible func type")
1334+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 7 inputs and 3 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
13321335
}
13331336
if sc, ok := c.(Func7x3); ok {
13341337
return sc

sdks/go/pkg/beam/core/util/reflectx/calls.tmpl

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515

1616
package reflectx
1717

18-
import "reflect"
18+
import (
19+
"reflect"
20+
"fmt"
21+
)
1922

2023
// Generated arity-specialized Func implementations to avoid runtime temporary
2124
// slices. Code that knows the arity can potentially avoid that overhead in
@@ -57,7 +60,7 @@ func (c *shimFunc{{$in}}x{{$out}}) Call{{$in}}x{{$out}}({{mkargs $in "arg%v" "in
5760

5861
func ToFunc{{$in}}x{{$out}}(c Func) Func{{$in}}x{{$out}} {
5962
if c.Type().NumIn() != {{$in}} || c.Type().NumOut() != {{$out}} {
60-
panic("incompatible func type")
63+
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want {{$in}} inputs and {{$out}} outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
6164
}
6265
if sc, ok := c.(Func{{$in}}x{{$out}}); ok {
6366
return sc

0 commit comments

Comments
 (0)