MCPcopy Index your code
hub / github.com/coder/coder / writeChildUnarchiveGuard

Method writeChildUnarchiveGuard

coderd/exp_chats.go:2929–2953  ·  view source on GitHub ↗

writeChildUnarchiveGuard returns a 400 early when a child unarchive request obviously races an archived parent. The durable invariant is enforced atomically in chatd.Server.UnarchiveChat; this guard just surfaces the error before we take any locks. Returns true when a response has been written.

(
	ctx context.Context,
	rw http.ResponseWriter,
	chat database.Chat,
)

Source from the content-addressed store, hash-verified

2927//
2928// Returns true when a response has been written.
2929func (api *API) writeChildUnarchiveGuard(
2930 ctx context.Context,
2931 rw http.ResponseWriter,
2932 chat database.Chat,
2933) bool {
2934 parent, err := api.Database.GetChatByID(ctx, chat.ParentChatID.UUID)
2935 if err != nil {
2936 if errors.Is(err, sql.ErrNoRows) {
2937 httpapi.ResourceNotFound(rw)
2938 return true
2939 }
2940 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
2941 Message: "Failed to load parent chat.",
2942 Detail: err.Error(),
2943 })
2944 return true
2945 }
2946 if parent.Archived {
2947 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
2948 Message: "Cannot unarchive a child chat while its parent is archived. Unarchive the parent chat to cascade.",
2949 })
2950 return true
2951 }
2952 return false
2953}
2954
2955// EXPERIMENTAL: this endpoint is experimental and is subject to change.
2956//

Callers 1

patchChatMethod · 0.95

Calls 5

ResourceNotFoundFunction · 0.92
WriteFunction · 0.92
GetChatByIDMethod · 0.65
IsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected