Skip to content

Commit 2466b51

Browse files
stilvoidbrianterry
authored andcommitted
Add some additional logging and capture all panics from the handler (#110)
1 parent 075aebd commit 2466b51

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

cfn/cfn.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,26 @@ type InvokeScheduler interface {
7373
// invocations of a custom resource and MakeTestEventFunc is the entry point that
7474
// allows the CLI's contract testing framework to invoke the resource's CRUDL handlers.
7575
func Start(h Handler) {
76+
defer func() {
77+
if r := recover(); r != nil {
78+
log.Printf("Handler panicked: %s", r)
79+
panic(r) // Continue the panic
80+
}
81+
}()
7682

7783
// MODE is an environment variable that is set ONLY
7884
// when contract test are performed.
7985
mode, _ := os.LookupEnv("MODE")
8086

8187
if mode == "Test" {
88+
log.Printf("Handler starting in test mode")
8289
lambda.Start(makeTestEventFunc(h))
8390
} else {
91+
log.Printf("Handler starting")
8492
lambda.Start(makeEventFunc(h))
8593
}
8694

95+
log.Printf("Handler finished")
8796
}
8897

8998
// Tags are stored as key/value paired strings
@@ -253,6 +262,7 @@ func makeEventFunc(h Handler) eventFunc {
253262
re := newReportErr(callbackAdapter, metricsPublisher)
254263

255264
handlerFn, err := router(event.Action, h)
265+
log.Printf("Handler received the %s action", event.Action)
256266

257267
if err != nil {
258268
return re.report(event, "router error", err, serviceInternalError)

0 commit comments

Comments
 (0)