From 7f2198cc76cf1507d1c41d49279421740fd6df28 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 14 Apr 2026 20:25:53 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20format-detection=20guard=20in=20collect-?= =?UTF-8?q?engagement.sh=20=E2=80=94=20fail=20loudly=20on=20non-JSON=20log?= =?UTF-8?q?s=20(#746)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 (1M context) --- site/collect-engagement.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/site/collect-engagement.sh b/site/collect-engagement.sh index dbc4826..e87e3aa 100644 --- a/site/collect-engagement.sh +++ b/site/collect-engagement.sh @@ -59,6 +59,21 @@ fi mkdir -p "$EVIDENCE_DIR" +# Verify input is Caddy JSON format (not Combined Log Format or other) +first_line=$(grep -m1 '.' "$CADDY_LOG" || true) +if [ -z "$first_line" ]; then + log "WARN: Caddy access log is empty at ${CADDY_LOG}" + echo "WARN: Caddy access log is empty — nothing to parse." >&2 + exit 0 +fi +if ! printf '%s\n' "$first_line" | jq empty 2>/dev/null; then + preview="${first_line:0:200}" + log "ERROR: Input file is not Caddy JSON format (expected structured JSON access log). Got: ${preview}" + echo "ERROR: Input file is not Caddy JSON format (expected structured JSON access log)." >&2 + echo "Got: ${preview}" >&2 + exit 1 +fi + # ── Parse access log ──────────────────────────────────────────────────────── log "Parsing ${CADDY_LOG} for entries since $(date -u -d "@${CUTOFF_TS}" +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || echo "${CUTOFF_TS}")" -- 2.49.1