Library › Coding AI › Software developers
Fix one line that set -e kills, and keep strict mode
Practice: Setting limits and rules. About 5 minutes.
About this exercise
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.
Common mistakes when you ask AI for this
- Dropping strict mode. The quick fix people suggest is removing set -e, which your team rule forbids. Try: Add: "Keep set -euo pipefail; fix only the count line."
- The whole script back. The AI reprints the script with other 'improvements'. Try: Say: "Give me only the corrected line."
- No reason given. Without the cause, the next script will hit the same bug. Try: Add: "One sentence: grep exits 1 when nothing matches."
What a strong prompt includes
- Keeps strict mode
- Asks for one line
- Asks why
- Caps the explanation
Related exercises
- Add a cron line that matches the others in a crontab (Coding AI · Product managers)
- Add dark mode by overriding your existing CSS variables (Coding AI · Software developers)
- Add input checks to your number guessing game (Coding AI · High school students)
- Add input validation to a Java method with exact messages (Coding AI · Software developers)
- Add labels to a signup form without rewriting the page (Coding AI · High school students)