nicer names, update copyright
authorIan Kelling <iank@fsf.org>
Wed, 4 Jul 2018 00:48:30 +0000 (20:48 -0400)
committerIan Kelling <iank@fsf.org>
Wed, 4 Jul 2018 00:52:05 +0000 (20:52 -0400)
README
err
err-allow-function [moved from errallow-function with 93% similarity]
err-bash-trace-function [moved from bash-trace-function with 96% similarity]
err-catch-function [moved from errcatch-function with 93% similarity]
err-exit-function [moved from errexit-function with 88% similarity]
gen-err [deleted file]
generate-err [new file with mode: 0755]

diff --git a/README b/README
index 180c18842f59280a33294e1c9f5a6c39ea2295b3..ff45665d4bb6f16fc4f736ecd90cdb44f99ffa94 100644 (file)
--- a/README
+++ b/README
@@ -1,10 +1,11 @@
 Functions to deal with errors in bash
 
-err: usually, just source this. contains the others and runs errcatch
+err: usually, just copy and source this. contains the other files
 
-errcatch: set a trap on error to do bash-trace and exit
-errallow: undo errcatch
-errexit: exit and print stack trace
+
+err-catch: set a trap on error to do bash-trace and exit
+err-allow: undo errcatch
+err-exit: exit and print stack trace
 bash-trace: print stack trace (best bash stack trace ever)
 
 the err* functions depend on bash-trace.
diff --git a/err b/err
index 57ea5421d50fa5a7a9779dea64c7f98a76b5e94a..70dd6b262e446638074eabf7dc21aac08e8e678b 100644 (file)
--- a/err
+++ b/err
@@ -1,6 +1,27 @@
 #!/bin/bash
+# Copyright 2018 Ian Kelling
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 # this file was generated from gen-err and meant to be sourced
-bash-trace() {
+err-allow() {
+    if [[ $1 ]]; then
+        echo "errallow help: Undo the complimentary errcatch function."
+    else
+        set +E +o pipefail; trap ERR
+    fi
+}
+err-bash-trace() {
     local -i argc_index=0 frame i start=${1:-1} max_indent=8 indent
     local source
     local extdebug=false
@@ -25,21 +46,14 @@ bash-trace() {
         echo \'
     done
 }
-errallow() {
-    if [[ $1 ]]; then
-        echo "errallow help: Undo the complimentary errcatch function."
-    else
-        set +E +o pipefail; trap ERR
-    fi
-}
-errcatch() {
+err-catch() {
     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
+        err-bash-trace 2
         set -e
         "${_errcatch_cleanup[@]}"
         echo "$0: exiting with code $err"
@@ -48,7 +62,7 @@ errcatch() {
     trap _err-trap ERR
     set -o pipefail
 }
-errexit() {
+err-exit() {
     exec >&2
     code=1
     if [[ $@ ]]; then
@@ -62,8 +76,8 @@ errexit() {
         fi
     fi
     echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]}"
-    bash-trace 2
+    err-bash-trace 2
     echo "$0: exiting with code $code"
     exit $err
 }
-errcatch
+err-catch-function
similarity index 93%
rename from errallow-function
rename to err-allow-function
index aff8593594cfc1ff17ec6b5c0e871309b4b03ebf..265c838af248d44259003f46ace8b87ad24dedb9 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/bash
-# Copyright (C) 2014 Ian Kelling
+# Copyright (C) 2018 Ian Kelling
 
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-errallow() {
+err-allow() {
     if [[ $1 ]]; then
         echo "errallow help: Undo the complimentary errcatch function."
     else
similarity index 96%
rename from bash-trace-function
rename to err-bash-trace-function
index 6f677aa4bf7e83699fdf5d95980d92c4e3a7db12..f46e165628dca1fd0d0f876b2b472452714180a4 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/bash
-# Copyright (C) 2015 Ian Kelling
+# Copyright (C) 2018 Ian Kelling
 
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
 # shopt -s extdebug
 # Also note, setting extdebug in your .bashrc causes spam in bash 4.4.
 
-bash-trace() {
+err-bash-trace() {
     local -i argc_index=0 frame i start=${1:-1} max_indent=8 indent
     local source
     local extdebug=false
similarity index 93%
rename from errcatch-function
rename to err-catch-function
index 4fb8c3748df196200b8c81a17d9bd7f9f86607ba..ccb21452d0755b32262b58db7e3266fa2f9e64b6 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/bash
-# Copyright (C) 2014 Ian Kelling
+# Copyright (C) 2018 Ian Kelling
 
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # While running that, we exit with set -e, no stack trace, as
 # err trap does not work within an error trap
 
-errcatch() {
+err-catch() {
     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
+        err-bash-trace 2
         set -e
         "${_errcatch_cleanup[@]}"
         echo "$0: exiting with code $err"
similarity index 88%
rename from errexit-function
rename to err-exit-function
index cbe211815921001efd17469924c057fece37bb41..e72f2f5f6c5d57d3e72823748e056b92b5f5bb9c 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/bash
-# Copyright (C) 2015 Ian Kelling
+# Copyright (C) 2018 Ian Kelling
 
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -13,8 +13,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-errexit() {
-    # usage: errexit [EXIT_CODE] [MESSAGE]
+err-exit() {
+    # usage: err-exit [EXIT_CODE] [MESSAGE]
     exec >&2
     code=1
     if [[ $@ ]]; then
@@ -28,7 +28,7 @@ errexit() {
         fi
     fi
     echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]}"
-    bash-trace 2
+    err-bash-trace 2
     echo "$0: exiting with code $code"
     exit $err
 }
diff --git a/gen-err b/gen-err
deleted file mode 100755 (executable)
index 236c3a7..0000000
--- a/gen-err
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/bash
-
-x="$(readlink -f "$BASH_SOURCE")"; cd ${x%/*} # directory of this file
-
-cat <<'EOF' >err
-#!/bin/bash
-# this file was generated from gen-err and meant to be sourced
-EOF
-sed -r '/^ *(#|$)/d' *-function >>err
-echo errcatch >>err
diff --git a/generate-err b/generate-err
new file mode 100755 (executable)
index 0000000..069e693
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/bash
+# Copyright 2018 Ian Kelling
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+x="$(readlink -f "$BASH_SOURCE")"; cd ${x%/*} # directory of this file
+
+cat <<'EOF' >err
+#!/bin/bash
+# Copyright 2018 Ian Kelling
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# this file was generated from generate-err and meant to be sourced
+EOF
+sed -r '/^ *(#|$)/d' *-function >>err
+echo err-catch >>err