-
Notifications
You must be signed in to change notification settings - Fork 570
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 panics, but pass-through is allowed too on the handler's error value
aws-lambda-go/lambda/errors.go
Lines 20 to 22 in caace58
| if ive, ok := invokeError.(messages.InvokeResponse_Error); ok { | |
| return &ive | |
| } |
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:
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:
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
aws-lambda-go/lambda/errors.go
Lines 35 to 46 in caace58
| func lambdaPanicResponse(err interface{}) *messages.InvokeResponse_Error { | |
| if ive, ok := err.(messages.InvokeResponse_Error); ok { | |
| return &ive | |
| } | |
| panicInfo := getPanicInfo(err) | |
| return &messages.InvokeResponse_Error{ | |
| Message: panicInfo.Message, | |
| Type: getErrorType(err), | |
| StackTrace: panicInfo.StackTrace, | |
| ShouldExit: true, | |
| } | |
| } |