refactor(cron): move the retained-stamp scrub into cron/jobs_error_text.py

Keeps cron/jobs.py at +1 instead of +5 for the follow-up: the loop sits
next to sanitize_persisted_error and _record_run_outcome calls it.

Refs #155355

Co-authored-by: Bear Huddleston <196404565+BearHuddleston@users.noreply.github.com>
This commit is contained in:
Maciej Lisiewski
2026-11-14 23:15:01 +01:00
parent 9356b60844
commit 36290777b8
2 changed files with 12 additions and 5 deletions

View File

@@ -2401,11 +2401,7 @@ def _record_run_outcome(
job["last_status"] = status or (
"error" if not success else ("delivery_failed" if delivery_failed else "ok"))
cancelled = status == "cancelled" # an operator stop is not a failure
# Sticky stamps written before #155355 can hold raw credentials, and every outcome below
# rewrites jobs.json while keeping whichever of them it doesn't replace: scrub them in place.
for retained in (job.get("last_failure"), job.get("last_fire_error")):
if isinstance(retained, dict) and retained.get("detail"):
retained["detail"] = jobs_error_text.sanitize_persisted_error(str(retained["detail"]))
jobs_error_text.scrub_retained_stamps(job)
job["last_error"] = None if success or cancelled else jobs_error_text.sanitize_persisted_error(error)
if success:
# Healthy run: drop the alert-once dedup markers so a FUTURE break re-alerts, and clear

View File

@@ -27,3 +27,14 @@ def sanitize_persisted_error(error: Optional[str]) -> Optional[str]:
logger.warning("Failed to redact cron error before persisting it", exc_info=True)
return "[REDACTED - redaction failed]"
return text[:MAX_PERSISTED_ERROR_CHARS]
def scrub_retained_stamps(job: dict) -> None:
"""Scrub, in place, the sticky stamps a run outcome keeps (``last_failure``, ``last_fire_error``).
Stamps written before #155355 can hold raw credentials, and every run outcome rewrites
jobs.json while keeping whichever of them it doesn't replace.
"""
for retained in (job.get("last_failure"), job.get("last_fire_error")):
if isinstance(retained, dict) and retained.get("detail"):
retained["detail"] = sanitize_persisted_error(str(retained["detail"]))