{"id":"code-dev-bash-grep-pipefail-one-line","audience":"developers","category":"coding","track":"coding","technique":"constraints","title":"Fix one line that set -e kills, and keep strict mode","free":false,"task":"The health-check script dies silently on quiet days. Keep set -euo pipefail (a team rule) and fix only the count line so a day with no errors gives count=0. Reply with exactly 1 code block containing just the corrected line, then one sentence under 25 words that says grep exits with status 1 when nothing matches.","materialLabel":"The script and what happened (attached to your prompt automatically)","material":"#!/usr/bin/env bash\n# healthcheck.sh - runs at 07:00 from cron on the Ridgeline web box\nset -euo pipefail\n\nlog=\"/var/log/ridgeline/app-$(date +%F).log\"\ncount=$(grep -c \"ERROR\" \"$log\")\n\nif [ \"$count\" -gt 50 ]; then\n  echo \"ALERT: $count errors today\" | mail -s \"Ridgeline errors\" oncall@ridgeline.test\nelse\n  echo \"ok: $count errors\"\nfi\n\n---- what happened ----\n$ ./healthcheck.sh ; echo \"exit=$?\"\nexit=1\n(no \"ok\" line printed, no email - on a day with zero errors)\n\n$ grep -c \"ERROR\" /var/log/ridgeline/app-2026-11-05.log ; echo \"exit=$?\"\n0\nexit=1\n\n---- notes ----\n- On busy days it works fine.\n- Joel suggested \"just delete set -e, it's annoying\".\n- Team rule from the 2025 postmortem: all scripts keep set -euo pipefail.","rules":[{"type":"codeBlocks","count":1},{"type":"maxCodeLines","max":1},{"type":"maxProseWords","max":25}],"mistakes":[{"title":"Dropping strict mode","why":"The quick fix people suggest is removing set -e, which your team rule forbids.","fix":"Add: \"Keep set -euo pipefail; fix only the count line.\"","checks":["r1"]},{"title":"The whole script back","why":"The AI reprints the script with other 'improvements'.","fix":"Say: \"Give me only the corrected line.\"","checks":["r0","maxCodeLines"]},{"title":"No reason given","why":"Without the cause, the next script will hit the same bug.","fix":"Add: \"One sentence: grep exits 1 when nothing matches.\"","checks":["r2","maxProseWords","codeBlocks"]}],"promptHints":[{"label":"Keeps strict mode","patterns":["set -e","pipefail","strict"]},{"label":"Asks for one line","patterns":["one line","only the (corrected|fixed|count) line","single line"]},{"label":"Asks why","patterns":["why","exit (code|status)"]},{"label":"Caps the explanation","patterns":["one sentence","\\d+\\s*words"]}],"hint":"The bug is one line, and the tempting fix breaks a team rule. Tell the AI what must stay, and that you want one line and one reason.","rubricLabels":["The code block contains only the corrected count line, such as count=$(grep -c \"ERROR\" \"$log\" || true), which still prints 0 when nothing matches","Keeps set -euo pipefail: the answer doesn't remove or change it, and doesn't add set +e","There is exactly one sentence after the code block, and it says grep exits with status 1 when no lines match"]}