Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bmoffatt committed Jan 24, 2024
1 parent 4f81bad commit 55f2e0a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lambda/invoke_loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func reportFailure(invoke *invoke, invokeErr *messages.InvokeResponse_Error) err
return fmt.Errorf("unexpected error occured when serializing the function error cause for X-Ray: %v", err)
}

if err := invoke.xfailure(bytes.NewReader(errorPayload), contentTypeJSON, causeForXRay); err != nil {
if err := invoke.failure(bytes.NewReader(errorPayload), contentTypeJSON, causeForXRay); err != nil {
return fmt.Errorf("unexpected error occurred when sending the function error to the API: %v", err)
}
return nil
Expand Down
14 changes: 1 addition & 13 deletions lambda/runtime_api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"log"
"net/http"
"runtime"

"github.com/aws/aws-lambda-go/lambda/messages"
)

const (
Expand Down Expand Up @@ -56,12 +54,6 @@ type invoke struct {
client *runtimeAPIClient
}

type failure struct {
WorkingDirectory string `json:"working_directory"`
Exceptions []messages.InvokeResponse_Error `json:"exceptions"`
Paths []string `json:"paths"`
}

// success sends the response payload for an in-progress invocation.
// Notes:
// - An invoke is not complete until next() is called again!
Expand All @@ -75,11 +67,7 @@ func (i *invoke) success(body io.Reader, contentType string) error {
// - The execution of the function process continues, and is billed, until next() is called again!
// - A Lambda Function continues to be re-used for future invokes even after a failure.
// If the error is fatal (panic, unrecoverable state), exit the process immediately after calling failure()
func (i *invoke) failure(body io.Reader, contentType string) error {
return i.xfailure(body, contentType, nil)
}

func (i *invoke) xfailure(body io.Reader, contentType string, causeForXRay []byte) error {
func (i *invoke) failure(body io.Reader, contentType string, causeForXRay []byte) error {
url := i.client.baseURL + i.id + "/error"
return i.client.post(url, body, contentType, causeForXRay)
}
Expand Down
8 changes: 4 additions & 4 deletions lambda/runtime_api_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestClientDoneAndError(t *testing.T) {
assert.NoError(t, err)
})
t.Run(fmt.Sprintf("happy Error with payload[%d]", i), func(t *testing.T) {
err := invoke.failure(bytes.NewReader(payload), contentTypeJSON)
err := invoke.failure(bytes.NewReader(payload), contentTypeJSON, nil)
assert.NoError(t, err)
})
}
Expand All @@ -105,7 +105,7 @@ func TestInvalidRequestsForMalformedEndpoint(t *testing.T) {
require.Error(t, err)
err = (&invoke{client: newRuntimeAPIClient("🚨")}).success(nil, "")
require.Error(t, err)
err = (&invoke{client: newRuntimeAPIClient("🚨")}).failure(nil, "")
err = (&invoke{client: newRuntimeAPIClient("🚨")}).failure(nil, "", nil)
require.Error(t, err)
}

Expand Down Expand Up @@ -145,7 +145,7 @@ func TestStatusCodes(t *testing.T) {
require.NoError(t, err)
})
t.Run("failure should not error", func(t *testing.T) {
err := invoke.failure(nil, "")
err := invoke.failure(nil, "", nil)
require.NoError(t, err)
})
} else {
Expand All @@ -158,7 +158,7 @@ func TestStatusCodes(t *testing.T) {
}
})
t.Run("failure should error", func(t *testing.T) {
err := invoke.failure(nil, "")
err := invoke.failure(nil, "", nil)
require.Error(t, err)
if i != 301 && i != 302 && i != 303 {
assert.Contains(t, err.Error(), "unexpected status code")
Expand Down

0 comments on commit 55f2e0a

Please sign in to comment.