From 82748f870f1602ba88c53d175e8e6724f465aca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Tue, 21 Apr 2026 15:24:54 +0400 Subject: [PATCH] Fix missing RowsAffected checks in cookie update methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Address PR review comments: capture Exec result and check RowsAffected() == 0 to return ErrResourceNotFound in Cookie.Update, CookieCategory.Update, and CookieCategory.UpdateRank. Also update coredata and relay contributor docs accordingly. Signed-off-by: Émile Ré --- contrib/claude/coredata.md | 8 +++++++- contrib/claude/relay.md | 2 +- pkg/coredata/cookie.go | 6 +++++- pkg/coredata/cookie_category.go | 12 ++++++++++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/contrib/claude/coredata.md b/contrib/claude/coredata.md index d677dc4fc..7a18f19a9 100644 --- a/contrib/claude/coredata.md +++ b/contrib/claude/coredata.md @@ -129,7 +129,13 @@ assets, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Asset]) *a = assets // Update / Delete — no RETURNING -_, err := conn.Exec(ctx, q, args) +result, err := conn.Exec(ctx, q, args) +if err != nil { + return err +} +if result.RowsAffected() == 0 { + return ErrResourceNotFound +} ``` ## Sentinel errors diff --git a/contrib/claude/relay.md b/contrib/claude/relay.md index 3e3f0cc98..e5dae5997 100644 --- a/contrib/claude/relay.md +++ b/contrib/claude/relay.md @@ -341,7 +341,7 @@ Relay directives handle connection updates automatically — no manual store man #### Connection setup -Any connection that a mutation will add to or remove from **must** have a `@connection` directive and expose `__id`: +Any connection that a mutation will add to or remove from **must** have a `@connection` directive. If the mutation needs the connection ID in the same fragment, expose `__id`; otherwise derive it with `ConnectionHandler.getConnectionID`: ```tsx const fragment = graphql` diff --git a/pkg/coredata/cookie.go b/pkg/coredata/cookie.go index 596d52575..4132c560e 100644 --- a/pkg/coredata/cookie.go +++ b/pkg/coredata/cookie.go @@ -327,7 +327,7 @@ WHERE } maps.Copy(args, scope.SQLArguments()) - _, err := tx.Exec(ctx, q, args) + result, err := tx.Exec(ctx, q, args) if err != nil { if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok { if pgErr.Code == "23505" && pgErr.ConstraintName == "idx_cookies_unique_name_per_banner" { @@ -337,6 +337,10 @@ WHERE return fmt.Errorf("cannot update cookie: %w", err) } + if result.RowsAffected() == 0 { + return ErrResourceNotFound + } + return nil } diff --git a/pkg/coredata/cookie_category.go b/pkg/coredata/cookie_category.go index 2d4298be3..d91e1cc9f 100644 --- a/pkg/coredata/cookie_category.go +++ b/pkg/coredata/cookie_category.go @@ -341,11 +341,15 @@ WHERE } maps.Copy(args, scope.SQLArguments()) - _, err := tx.Exec(ctx, q, args) + result, err := tx.Exec(ctx, q, args) if err != nil { return fmt.Errorf("cannot update cookie category: %w", err) } + if result.RowsAffected() == 0 { + return ErrResourceNotFound + } + return nil } @@ -390,11 +394,15 @@ WHERE %s } maps.Copy(args, scope.SQLArguments()) - _, err := tx.Exec(ctx, q, args) + result, err := tx.Exec(ctx, q, args) if err != nil { return fmt.Errorf("cannot update cookie category rank: %w", err) } + if result.RowsAffected() == 0 { + return ErrResourceNotFound + } + return nil }