From 671577245ab9ac2d3a10957b8dd8fffe2eaed5a0 Mon Sep 17 00:00:00 2001 From: Head of Product & Engineering Date: Mon, 6 Apr 2026 14:12:36 +0200 Subject: [PATCH] fix: use sentinel ErrLocationNotFound to satisfy errorlint Replace errors.New("location not found") string with a package-level sentinel var so callers can use errors.Is() instead of string comparison, which errorlint flags as unsafe. Co-Authored-By: Paperclip --- internal/ghl/admin.go | 3 ++- internal/store/mongo.go | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/ghl/admin.go b/internal/ghl/admin.go index 5e1ea92..de9ecdc 100644 --- a/internal/ghl/admin.go +++ b/internal/ghl/admin.go @@ -3,6 +3,7 @@ package ghl import ( "context" "encoding/json" + "errors" "io" "log/slog" "net/http" @@ -153,7 +154,7 @@ func (h *AdminHandler) HandleSetLocationConfig(w http.ResponseWriter, r *http.Re if err := h.store.UpdateLocationConfig(ctx, locationID, payload.SenderID, payload.CastAPIKey); err != nil { slog.Error("admin: update location config failed", "location_id", locationID, "err", err) - if err.Error() == "location not found" { + if errors.Is(err, store.ErrLocationNotFound) { http.Error(w, "location not found", http.StatusNotFound) return } diff --git a/internal/store/mongo.go b/internal/store/mongo.go index 18d32fd..f4fe8b6 100644 --- a/internal/store/mongo.go +++ b/internal/store/mongo.go @@ -10,6 +10,9 @@ import ( "go.mongodb.org/mongo-driver/v2/mongo/options" ) +// ErrLocationNotFound is returned when a location ID has no stored token record. +var ErrLocationNotFound = errors.New("location not found") + type TokenRecord struct { LocationID string `bson:"location_id"` CompanyID string `bson:"company_id"` @@ -99,7 +102,7 @@ func (s *Store) UpdateLocationConfig(ctx context.Context, locationID, senderID, return err } if res.MatchedCount == 0 { - return errors.New("location not found") + return ErrLocationNotFound } return nil }