From 9deb8e85f9e35aa4030a2beb3f5adb482b470616 Mon Sep 17 00:00:00 2001 From: kmtym1998 Date: Sun, 20 Aug 2023 18:10:40 +0900 Subject: [PATCH] api: Log errors when executing setup and teardown This commit adds error logging when executing the setup and teardown functions in the k6 API. If an error occurs during setup or teardown, it will now be logged with the corresponding error message. This improves error reporting and makes it easier to diagnose issues related to setup and teardown. Related issue: #2422 --- api/v1/setup_teardown_routes.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/v1/setup_teardown_routes.go b/api/v1/setup_teardown_routes.go index 61ec87116bf..66abadbab54 100644 --- a/api/v1/setup_teardown_routes.go +++ b/api/v1/setup_teardown_routes.go @@ -71,6 +71,7 @@ func handleRunSetup(cs *ControlSurface, rw http.ResponseWriter, r *http.Request) runner := cs.RunState.Runner if err := cs.RunState.Runner.Setup(r.Context(), cs.Samples); err != nil { + cs.RunState.Logger.WithError(err).Error("Error executing setup") apiError(rw, "Error executing setup", err.Error(), http.StatusInternalServerError) return } @@ -81,6 +82,7 @@ func handleRunSetup(cs *ControlSurface, rw http.ResponseWriter, r *http.Request) // handleRunTeardown executes the runner's Teardown() method func handleRunTeardown(cs *ControlSurface, rw http.ResponseWriter, r *http.Request) { if err := cs.RunState.Runner.Teardown(r.Context(), cs.Samples); err != nil { + cs.RunState.Logger.WithError(err).Error("Error executing teardown") apiError(rw, "Error executing teardown", err.Error(), http.StatusInternalServerError) } }