Skip to content

Commit f822661

Browse files
fix differentiation between error and non-error (#2)
1 parent 08b4cf7 commit f822661

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

Diff for: .github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Set up Go
1818
uses: actions/setup-go@v2
1919
with:
20-
go-version: 1.17
20+
go-version: 1.18
2121

2222
- name: Build
2323
run: make compile-lambda-linux-all

Diff for: cmd/localstack/custom_interop.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ func NewCustomInteropServer(lsOpts *LsOpts, delegate rapidcore.InteropServer, lo
100100
NeedDebugLogs: true,
101101
InvokedFunctionArn: invokeR.InvokedFunctionArn,
102102
})
103+
if err != nil {
104+
log.Fatalln(err)
105+
}
103106
inv := GetEnvOrDie("AWS_LAMBDA_FUNCTION_TIMEOUT")
104107
timeoutDuration, _ := time.ParseDuration(inv + "s")
105108
memorySize := GetEnvOrDie("AWS_LAMBDA_FUNCTION_MEMORY_SIZE")
@@ -111,21 +114,23 @@ func NewCustomInteropServer(lsOpts *LsOpts, delegate rapidcore.InteropServer, lo
111114
// TODO: handle err
112115
}
113116

114-
callErr := false
115-
var errR ErrorResponse
116-
err := json.Unmarshal(invokeResp.Body, &errR)
117-
if err == nil {
118-
callErr = true
119-
} else {
120-
log.Error(err)
117+
var errR map[string]any
118+
marshalErr := json.Unmarshal(invokeResp.Body, &errR)
119+
120+
if marshalErr != nil {
121+
log.Fatalln(marshalErr)
121122
}
122123

123-
if callErr {
124+
_, isErr := errR["errorType"]
125+
126+
if isErr {
127+
log.Infoln("Sending to /error")
124128
_, err = http.Post(server.upstreamEndpoint+"/invocations/"+invokeR.InvokeId+"/error", "application/json", bytes.NewReader(invokeResp.Body))
125129
if err != nil {
126130
log.Error(err)
127131
}
128132
} else {
133+
log.Infoln("Sending to /response")
129134
_, err = http.Post(server.upstreamEndpoint+"/invocations/"+invokeR.InvokeId+"/response", "application/json", bytes.NewReader(invokeResp.Body))
130135
if err != nil {
131136
log.Error(err)

Diff for: cmd/localstack/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func main() {
6969
go sandbox.Create()
7070

7171
// start runtime init
72-
go InitHandler(sandbox, "$LATEST", 30) // TODO: replace this with a custom init
72+
go InitHandler(sandbox, GetEnvOrDie("AWS_LAMBDA_FUNCTION_VERSION"), 30) // TODO: replace this with a custom init
7373

7474
// TODO: make the tracing server optional
7575
// start blocking with the tracing server

0 commit comments

Comments
 (0)