refactor: change existence-check helpers to return (bool, error)
Follow-up to #4484, which kept the bool-only signature for FeedExists, CategoryFeedExists (internal/storage/feed.go), and CategoryIDExists (internal/storage/category.go) and instead logged a real query/connection error via slog before returning false -- deliberately narrow, since changing the signature would touch every call site. This does that follow-up: all three now return (bool, error), and every call site (14 total, across internal/api, internal/ui, internal/reader/handler, and internal/validator) is updated to distinguish a genuine backend failure from "resource not found": - internal/api/*_handlers.go: response.JSONServerError on a real error, existing response.JSONNotFound/JSONBadRequest behavior unchanged otherwise. - internal/ui/*.go: response.HTMLServerError on a real error, existing response.HTMLNotFound behavior unchanged otherwise. - internal/reader/handler/handler.go: locale.NewLocalizedErrorWrapper(err, "error.database_error", err) on a real error, matching the exact idiom already used elsewhere in this same file for other storage errors. - internal/validator/feed.go: *locale.LocalizedError (unlike *locale.LocalizedErrorWrapper used elsewhere) has no way to carry an underlying error, so a signature change here would be a separate, larger change to the validator package's error model. Logs the real error via slog and falls back to the existing "error.feed_category_not_found" message, same as before -- this is a deliberate scoping decision, not an oversight, and is called out in the PR description. Testing: go build ./..., go vet ./..., gofmt -l (clean on all 10 touched files), and the full go test ./... suite (48 packages, all pass, no existing test called these 3 functions directly). No new test added, same reasoning as #4484: no DB-error-injection harness exists for this package, and this change doesn't alter behavior when there's no error -- every touched call site's non-error branch is behaviorally identical to before.
S
shiyongjiang committed
69756868dd1edbe62801c3a2a214c59d286320ce
Parent: 2bc9f30
Committed by fguillot <323546+fguillot@users.noreply.github.com>
on 8/5/2026, 7:43:17 PM