Skip to content

Commit 1a44858

Browse files
joe4devclaude
andcommitted
fix(init): include requestId in init error response even when empty
Use *string for the RequestId field in ErrorResponse so that an empty string is serialized (not omitted by omitempty), while nil — used for fault events — stays omitted. Fixes test_lambda_runtime_error snapshot mismatch where requestId: "" was expected but absent. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1e8a632 commit 1a44858

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎cmd/localstack/custom_interop.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func (l *LocalStackAdapter) SendResult(invokeId string, body []byte, isError boo
8282
return err
8383
}
8484

85+
8586
func NewCustomInteropServer(lsOpts *LsOpts, adapter *LocalStackAdapter, delegate interop.Server, logCollector *LogCollector) (server *CustomInteropServer) {
8687
server = &CustomInteropServer{
8788
delegate: delegate.(*rapidcore.Server),
@@ -220,10 +221,11 @@ func (c *CustomInteropServer) SendInitErrorResponse(resp *interop.ErrorInvokeRes
220221
return c.delegate.SendInitErrorResponse(resp)
221222
}
222223

224+
requestId := c.delegate.GetCurrentInvokeID()
223225
adaptedResp := lsapi.ErrorResponse{
224226
ErrorMessage: parsed.ErrorMessage,
225227
ErrorType: parsed.ErrorType,
226-
RequestId: c.delegate.GetCurrentInvokeID(),
228+
RequestId: &requestId,
227229
StackTrace: parsed.StackTrace,
228230
}
229231
body, err := json.Marshal(adaptedResp)

‎cmd/localstack/events.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/interop"
99
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/rapidcore/standalone/telemetry"
10+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lsapi"
1011
)
1112

1213
// LocalStackEventsAPI intercepts fault events and forwards them to LocalStack as error status callbacks.
@@ -34,7 +35,7 @@ func (ev *LocalStackEventsAPI) SendFault(data interop.FaultData) error {
3435
ev.mu.RUnlock()
3536
}
3637

37-
resp := ErrorResponse{
38+
resp := lsapi.ErrorResponse{
3839
ErrorMessage: fmt.Sprintf("RequestId: %s Error: %s", requestID, data.ErrorMessage),
3940
ErrorType: string(data.ErrorType),
4041
}

‎internal/lsapi/types.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type LogResponse struct {
1717
type ErrorResponse struct {
1818
ErrorMessage string `json:"errorMessage"`
1919
ErrorType string `json:"errorType,omitempty"`
20-
RequestId string `json:"requestId,omitempty"`
21-
StackTrace []string `json:"stackTrace,omitempty"`
20+
// RequestId uses *string so that an empty string "" is serialized (not omitted),
21+
// while nil is omitted — init errors always set this field, fault events leave it nil.
22+
RequestId *string `json:"requestId,omitempty"`
23+
StackTrace []string `json:"stackTrace,omitempty"`
2224
}

0 commit comments

Comments
 (0)