skill-shell-script-no-error-handling
Shell script lacks error handling (set -e or set -euo pipefail)
Rule Details
Without proper error handling, shell scripts continue executing after a command fails, which can cause cascading issues and data corruption. This rule checks .sh and .bash files for the presence of set -e, set -euo pipefail, or a trap ... ERR handler. If none are found, a warning is reported with an auto-fix that inserts set -euo pipefail after the shebang line.
Incorrect
Script with no error handling
#!/bin/bash
echo "Building..."
npm run build
echo "Deploying..."
npm run deployCorrect
Script with set -euo pipefail
#!/bin/bash
set -euo pipefail
echo "Building..."
npm run build
echo "Deploying..."
npm run deployScript with trap-based error handling
#!/bin/bash
trap 'echo "Error on line $LINENO"; exit 1' ERR
npm run buildHow To Fix
Add set -euo pipefail immediately after the shebang line. This causes the script to exit on any command failure (-e), undefined variable usage (-u), and pipe failures (-o pipefail). The auto-fixer inserts this line automatically.
Options
This rule does not have any configuration options.
Related Rules
Resources
Version
Available since: v0.2.0