refactor: use errors.Is()/errors.AsType() for error comparison and rename shadowed variables

Replace direct error equality checks (err == pgx.ErrNoRows, err != http.ErrServerClosed)
with the idiomatic errors.Is() function throughout handlers, services, middleware, and app
startup. This correctly handles wrapped error chains.

Also replace a raw type assertion (*HTTPError) with errors.AsType[*HTTPError]() in the
error handler middleware for consistency.

Additionally, rename shadowed variables for clarity:
- sidecar.go: config -> sidecarConfig, systemConfig (shadowed package-level vars)
- media_scanner.go: uuid -> uuidString (shadowed the uuid package import)
This commit is contained in:
2026-04-20 21:20:22 -04:00
parent d8d6334052
commit 9ccff320a1
15 changed files with 59 additions and 45 deletions
+2 -1
View File
@@ -6,6 +6,7 @@ import (
"bookhoard/internal/services"
"bookhoard/templates"
"bytes"
"errors"
"fmt"
"net/http"
@@ -73,7 +74,7 @@ func registerReaderRoutes(cfg *Config) {
MediaItemID: pgtype.UUID{Bytes: parsedUUID, Valid: true},
UserID: uuidToPGType(userUUID),
})
if err != nil && err != pgx.ErrNoRows {
if err != nil && !errors.Is(err, pgx.ErrNoRows) {
progress = database.ReadingProgress{}
}
// Get bookmarks