Skip to content

handler.validateReturns() panics on function with no return value #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mlctrez opened this issue Jan 16, 2018 · 3 comments · Fixed by #9
Closed

handler.validateReturns() panics on function with no return value #3

mlctrez opened this issue Jan 16, 2018 · 3 comments · Fixed by #9

Comments

@mlctrez
Copy link

mlctrez commented Jan 16, 2018

The validateReturns method panics with runtime: index out of range for a handler function with no return value. Tested with go v1.9.2

Adding this test case in lambda/handler_test.go:

{
	name:     "no return value should not result in error",
	expected: nil,
	handler: func() {
	},
},

results in

panic: runtime error: index out of range [recovered]
	panic: runtime error: index out of range

goroutine 18 [running]:
testing.tRunner.func1(0xc420152b40)
	/usr/local/go/src/testing/testing.go:711 +0x2d2
panic(0x138f900, 0x15f9800)
	/usr/local/go/src/runtime/panic.go:491 +0x283
reflect.(*rtype).Out(0x1369c00, 0x0, 0x1393940, 0xc420016a88)
	/usr/local/go/src/reflect/type.go:1043 +0xc7
github.com/aws/aws-lambda-go/lambda.validateReturns(0x15d3040, 0x1369c00, 0x1369c00, 0x0)
	/Users/mattman/go/src/github.com/aws/aws-lambda-go/lambda/handler.go:64 +0x1c6

Line 63 in handler.go needs to check for at least one return value before performing the type check.

	} else if handler.NumOut() > 0 {
		if !handler.Out(0).Implements(errorType) {
@bmoffatt
Copy link
Collaborator

Feel free to create a PR to fix this up. Otherwise I'll make the change later this afternoon.

dlsniper added a commit to dlsniper/aws-lambda-go that referenced this issue Jan 16, 2018
This fixes a panic when invoking validateReturns() on a function without
returns. Fixes aws#3
@dlsniper
Copy link
Contributor

I've bumped into the same thing and I've sent #9

bmoffatt pushed a commit that referenced this issue Jan 16, 2018
This fixes a panic when invoking validateReturns() on a function without
returns. Fixes #3
@mlctrez
Copy link
Author

mlctrez commented Jan 16, 2018

Thanks @dlsniper !

carlzogh pushed a commit that referenced this issue Jul 5, 2021
Catching up to current Master Fork
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants