Skip to content

Commit 3cd4328

Browse files
committed
Fix panic in handler.validateReturns()
This fixes a panic when invoking validateReturns() on a function without returns. Fixes aws#3
1 parent 41c45fa commit 3cd4328

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lambda/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func validateReturns(handler reflect.Type) error {
5858
if !handler.Out(1).Implements(errorType) {
5959
return fmt.Errorf("handler returns two values, but the second does not implement error")
6060
}
61-
} else {
61+
} else if handler.NumOut() == 1 {
6262
if !handler.Out(0).Implements(errorType) {
6363
return fmt.Errorf("handler returns a single value, but it does not implement error")
6464
}

lambda/handler_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,17 @@ func TestInvalidHandlers(t *testing.T) {
6363
return "hello"
6464
},
6565
},
66+
{
67+
name: "no return value should not result in error",
68+
expected: nil,
69+
handler: func() {
70+
},
71+
},
6672
}
6773
for i, testCase := range testCases {
6874
t.Run(fmt.Sprintf("testCase[%d] %s", i, testCase.name), func(t *testing.T) {
6975
lambdaHandler := newHandler(testCase.handler)
7076
_, err := lambdaHandler.Invoke(context.TODO(), make([]byte, 0))
71-
assert.NotNil(t, err)
7277
assert.Equal(t, testCase.expected, err)
7378
})
7479
}

0 commit comments

Comments
 (0)