From 3e73a582ba0bd637fb95980bfe9ee4374e8e2d2b Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Mon, 20 Apr 2026 20:45:35 -0400 Subject: [PATCH] refactor(handlers): use errors.Is() for pgx error comparison in KOReader Replace direct equality checks (err != pgx.ErrNoRows) with the idiomatic errors.Is(err, pgx.ErrNoRows) pattern. This is the recommended Go practice for error comparison as it correctly handles wrapped errors from error chains, making the code more robust against future refactoring that might wrap errors with fmt.Errorf and %w. --- internal/handlers/koreader.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/handlers/koreader.go b/internal/handlers/koreader.go index c4db8f9..1f721f0 100644 --- a/internal/handlers/koreader.go +++ b/internal/handlers/koreader.go @@ -4,6 +4,7 @@ import ( "bookhoard/internal/database" wsync "bookhoard/internal/sync" "encoding/json" + "errors" "fmt" "net/http" "time" @@ -401,11 +402,11 @@ func (h *KOReaderHandler) updateProgressForBook(c *echo.Context, userID pgtype.U UserID: userID, }) - if err != nil && err != pgx.ErrNoRows { + if err != nil && !errors.Is(err, pgx.ErrNoRows) { return err } - hasExistingProgress := err != pgx.ErrNoRows + hasExistingProgress := !errors.Is(err, pgx.ErrNoRows) conflictDetected := false if hasExistingProgress && existingProgress.LastSyncSource.Valid {