What is the difference between trap EXIT and trap ERR in bash?
EXIT fires every time the script exits, regardless of why — success, failure, or Ctrl+C. ERR fires only when a command returns a non-zero exit code, and only when set -e is active. For cleanup that must always run, use EXIT. For logging failures at the exact line they occur, use ERR.