From bf8b73a01be39eb8f2baac4ee354954dc0c6793d Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Fri, 17 Jun 2016 00:38:13 -0700 Subject: [PATCH] better output --- README | 25 ++++++++++++++++--------- errcatch-function | 3 +-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README b/README index b3829e2..7458586 100644 --- a/README +++ b/README @@ -1,12 +1,19 @@ -The main documentation is availiable via --help and near the top of any bash -script files which sit next to this file. +Functions to deal with errors in bash. -Files ending in -function are for sourcing then calling as a function. Files -without -function are exactly the same except they are for calling as a script. +bash-trace: print stack trace (best bash stack trace ever). +errcatch: on error, do stack trace ane exit +errallow: undo errcatch +errexit: exit and print stack trace -Patches, bugs, and any feedback is very welcome via gitorious or email to -Ian Kelling . +the err* functions depend on bash-trace. + + +For scripts which don't or hardly contains functions, this is usually sufficient: +set -eE -o pipefail +trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR -This program is also part of a collection of programs, -https://gitorious.org/bash-programs-by-ian, which are unrelated except -having the same author and being being bash programs. + +Related: see my bash script template repo. + +Patches, bugs, and any feedback is very welcome via email to +Ian Kelling . diff --git a/errcatch-function b/errcatch-function index b6489ac..bf60d0c 100644 --- a/errcatch-function +++ b/errcatch-function @@ -13,13 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -# on non-zero return codes outside of if/else,etc, print failure, stack trace, and exit -# depends on bash-trace function errcatch() { set -E; shopt -s extdebug _err-trap() { err=$? exec >&2 + set +x echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]}:in \`$BASH_COMMAND' returned $err" bash-trace 2 echo "$0: exiting with code $err" -- 2.25.1