Redact recipe-candidate failures in logs
CI / ci (push) Successful in 2m29s
CI / ci (pull_request) Successful in 2m41s

A recipe-candidates request whose stored-recipe lookup failed logged the
error unchanged, and that error quotes the search result's URL, which can
carry a personal token, along with the database error text.

dinners.Service.Candidates now wraps every failure other than a missing
dinner in ErrCandidatesFailed, and writeDinnerError logs it as a fixed
reason (candidates_failed) with the dinner id only, answering 500
internal. Not-found, not-configured and search-failed responses are
unchanged.

Fixes MQ-98-06 (Maestro 3759a975-f937-4284-81a2-9e61345a3aa3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-07 00:31:08 -04:00
co-authored by Claude Opus 5.5
parent 4a209623f5
commit 9cb8812ad8
4 changed files with 78 additions and 5 deletions
+8 -1
View File
@@ -205,7 +205,8 @@ func actorOrFail(w http.ResponseWriter, r *http.Request, logger *slog.Logger) (a
// an archived dinner is 409 dinner_archived and one changed while grounding
// 409 ground_conflict. Any other grounding failure, by candidate, link or
// manual recipe, wraps dinners.ErrGroundFailed and is 500, logged by reason
// and dinner id only.
// and dinner id only, as is any other failure finding candidates, which
// wraps dinners.ErrCandidatesFailed.
func writeDinnerError(w http.ResponseWriter, r *http.Request, logger *slog.Logger, action string, err error) {
var invalid *dinners.ValidationError
var dup *dinners.DuplicateError
@@ -231,6 +232,12 @@ func writeDinnerError(w http.ResponseWriter, r *http.Request, logger *slog.Logge
// logged.
logger.ErrorContext(r.Context(), action, "reason", "ground_failed", "dinner_id", chi.URLParam(r, "id"))
writeError(w, r, logger, http.StatusInternalServerError, "internal", "internal error")
case errors.Is(err, dinners.ErrCandidatesFailed):
// The error may quote a candidate's URL, which can carry a
// personal token, and dependency errors, so only the reason and
// dinner are logged.
logger.ErrorContext(r.Context(), action, "reason", "candidates_failed", "dinner_id", chi.URLParam(r, "id"))
writeError(w, r, logger, http.StatusInternalServerError, "internal", "internal error")
case errors.Is(err, dinners.ErrArchived):
writeError(w, r, logger, http.StatusConflict, "dinner_archived", "the dinner is archived")
case errors.Is(err, dinners.ErrGroundConflict):