aws / aws/aws-lambda-go

Enable propogation of fatal errors through io.Reader responses

Open
#504 0 comments 0 reactions 1 assignee Claimed by @bmoffatt View on GitHub
type/ux
Dominant language
Go
Stars
3.8k
Forks
578
Avg merge
8h 18m
Merged PRs (30d)
1

Description

**Is your feature request related to a problem? Please describe.**

A handler can gracefully force the process to be restarted by returning a `messages.InvokeResponse_Error` with `ShouldExit = true`. The usual way this happens is when the function `panic`s, but pass-through is allowed too on the handler's error value https://github.com/aws/aws-lambda-go/blob/caace586bdec3652223cc7761cc8c1c155a85601/lambda/errors.go#L20-L22

However, there's not an equivalent when the response value is a reader.

**Describe the solution you'd like**

Goal should be able to make this:
```go
type fatalReader struct{}
func (r *fatalReader) Read(_ []byte) (int, error) {
return 0, messages.InvokeResponse_Error{Type: "IDK", Message: "fatal", ShouldExit: true}
}
func handler() (any, error) {
return fatalReader{}, nil
}
```

result in the same logging and error reporting as this:
```go
func hander() (any, error) {
return nil, messages.InvokeResponse_Error{Type: "IDK", Message: "fatal", ShouldExit: true}
}
```

**Describe alternatives you've considered**

Might also expose something like https://github.com/aws/aws-lambda-go/blob/caace586bdec3652223cc7761cc8c1c155a85601/lambda/errors.go#L35-L46 in the public API, to make the construction of these fatal errors easier.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.