Skip to content

Bug: LambdaWrapper panics at runtime when panic occurs inside a lambda handler with multiple return values #70

Description

@MatejBalantic

When a lambda handler with several return values is wrapped using LambdaWrapper, and a panic is called from inside the handler, runtime error "reflect: wrong return count from function created by MakeFunc" occurs

Example of lambda handler:

client.LambdaWrapper(func() (string, error) {
	panic(err)
})

Here's a unit test to prove the bug

#client_test.go

func TestLambdaWrapperWithErrorAndMultipleReturnValues(t *testing.T) {
	client := testClient()
	err := errors.New("bork")

	defer func() {
		recoveredError := recover()

		if recoveredError != err {
			if recoveredError == nil {
				t.Error("Expected wrapper to bubble up the custom panic error")
			} else {
				t.Errorf("Unexpected panic %s", recoveredError)
			}
		}

		if transport, ok := client.Transport.(*TestTransport); ok {
			if transport.Body == nil {
				t.Error("Expected Body to be present")
			}
			if !transport.WaitCalled {
				t.Error("Expected wait to be called")
			}
		} else {
			t.Fail()
		}
	}()

	handler := client.LambdaWrapper(func() (string, error) {
		panic(err)
		return "", nil
	})
	fn := reflect.ValueOf(handler)
	var args []reflect.Value
	fn.Call(args)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions