Skip to content

Enable propogation of fatal errors through io.Reader responses #504

Open
@bmoffatt

Description

@bmoffatt

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

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

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,
}
}
in the public API, to make the construction of these fatal errors easier.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions