getChatDebugRun returns a single debug run with its steps. EXPERIMENTAL nolint:revive // get-return: revive assumes get* must be a getter, but this is an HTTP handler.
(rw http.ResponseWriter, r *http.Request)
| 7896 | // |
| 7897 | //nolint:revive // get-return: revive assumes get* must be a getter, but this is an HTTP handler. |
| 7898 | func (api *API) getChatDebugRun(rw http.ResponseWriter, r *http.Request) { |
| 7899 | ctx := r.Context() |
| 7900 | chat := httpmw.ChatParam(r) |
| 7901 | |
| 7902 | runIDStr := chi.URLParam(r, "debugRun") |
| 7903 | runID, err := uuid.Parse(runIDStr) |
| 7904 | if err != nil { |
| 7905 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 7906 | Message: "Invalid debug run ID.", |
| 7907 | Detail: err.Error(), |
| 7908 | }) |
| 7909 | return |
| 7910 | } |
| 7911 | |
| 7912 | run, err := api.Database.GetChatDebugRunByID(ctx, runID) |
| 7913 | if err != nil { |
| 7914 | // Treat both not-found and authorization failures as 404 to |
| 7915 | // avoid leaking the existence of runs the caller cannot access. |
| 7916 | if httpapi.Is404Error(err) { |
| 7917 | httpapi.ResourceNotFound(rw) |
| 7918 | return |
| 7919 | } |
| 7920 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 7921 | Message: "Internal error fetching debug run.", |
| 7922 | Detail: err.Error(), |
| 7923 | }) |
| 7924 | return |
| 7925 | } |
| 7926 | |
| 7927 | // Verify the run belongs to this chat. |
| 7928 | if run.ChatID != chat.ID { |
| 7929 | httpapi.ResourceNotFound(rw) |
| 7930 | return |
| 7931 | } |
| 7932 | |
| 7933 | steps, err := api.Database.GetChatDebugStepsByRunID(ctx, run.ID) |
| 7934 | if err != nil { |
| 7935 | // The run may have been deleted or access may have changed |
| 7936 | // between the two queries. Treat not-found/authz errors as |
| 7937 | // 404 for consistency with the run lookup above. |
| 7938 | if httpapi.Is404Error(err) { |
| 7939 | httpapi.ResourceNotFound(rw) |
| 7940 | return |
| 7941 | } |
| 7942 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 7943 | Message: "Internal error fetching debug steps.", |
| 7944 | Detail: err.Error(), |
| 7945 | }) |
| 7946 | return |
| 7947 | } |
| 7948 | |
| 7949 | httpapi.Write(ctx, rw, http.StatusOK, db2sdk.ChatDebugRunDetail(run, steps)) |
| 7950 | } |
no test coverage detected