Skip to content

Commit

Permalink
Merge pull request #69 from TravelPlaylist/master
Browse files Browse the repository at this point in the history
Fix a bug where multiple returns in lambda handler cause runtime errror
  • Loading branch information
waltjones authored Nov 26, 2019
2 parents 7d6c0bd + 6425299 commit 4b2c800
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 9 deletions.
5 changes: 4 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,10 @@ func (c *Client) LambdaWrapper(handlerFunc interface{}) interface{} {
handler := func(args []reflect.Value) []reflect.Value {
defer func() {
err := recover()
c.LogPanic(err, true)
if err != nil {
c.LogPanic(err, true)
panic(err)
}
}()

ret := handlerValue.Call(args)
Expand Down
64 changes: 56 additions & 8 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,30 @@ type TestMessage struct {
func TestLambdaWrapperWithError(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()
}
}()

//ctx := context.TODO()
handler := client.LambdaWrapper(func() {
panic(err)
Expand All @@ -293,17 +317,41 @@ func TestLambdaWrapperWithError(t *testing.T) {
var args []reflect.Value
fn.Call(args)
//testCallLambdaHandler(handler)
}

if transport, ok := client.Transport.(*TestTransport); ok {
if transport.Body == nil {
t.Error("Expected Body to be present")
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.WaitCalled {
t.Error("Expected wait to be called")

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()
}
} else {
t.Fail()
}
}()

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

func TestLambdaWrapperWithContext(t *testing.T) {
Expand Down

0 comments on commit 4b2c800

Please sign in to comment.