error-functions.sh 626 B

12345678910111213141516171819
  1. # Some error handling functions
  2. SCRIPTNAME=`echo "$0"|sed 's!.*/!!'`
  3. function info() { echo `date +%c` "${SCRIPTNAME}"\: info: "$@" 1>&2; }
  4. function warn() { echo `date +%c` "${SCRIPTNAME}"\: warning: "$@" 1>&2; }
  5. function error() { echo `date +%c` "${SCRIPTNAME}"\: error: "$@" 1>&2; }
  6. # Temporary debug messages
  7. # DEBUG=1 debug foo
  8. function debug() { [[ -v DEBUG ]] && echo `date +%c` "${SCRIPTNAME}"\: debug: "$@" 1>&2 || true ; }
  9. function die() {
  10. exit_code=1
  11. if [[ -v 2 ]]; then
  12. exit_code="${1}"
  13. shift;
  14. fi
  15. echo `date +%c` "${SCRIPTNAME}"\: fatal: "$@" 1>&2 && exit "${exit_code}";
  16. }