commit:     ee5ecbda72c1b6f39878ef16d52d48a4d7d0636d
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Tue Feb 14 00:38:12 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Feb 14 03:39:49 2023 +0000
URL:        
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=ee5ecbda

Have _eend() show the name of the calling function in its diagnostics

Currently, the diagnostic message reports that an invalid argument was
given to "_eend". Given that it is intended as a private function, users
of this library would be better off seeing the name of the function that
they originally invoked. Make it possible by having eend(), ewend(),
veend() and vewend() set the CALLER variable in the execution
environment of _eend(), duly affecting the content of the message.

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 functions.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/functions.sh b/functions.sh
index 28764d8..82d2192 100644
--- a/functions.sh
+++ b/functions.sh
@@ -249,7 +249,7 @@ _eend()
        if [ "$#" -eq 0 ]; then
                retval=0
        elif ! is_int "$1" || [ "$1" -lt 0 ]; then
-               printf 'Invalid argument given to _eend (the exit status code 
must be an integer >= 0)\n' >&2
+               printf 'Invalid argument given to %s (the exit status code must 
be an integer >= 0)\n' "${CALLER}" >&2
                retval=0
                shift
        else
@@ -286,7 +286,7 @@ eend()
 {
        local retval
 
-       _eend eerror "$@"
+       CALLER=${CALLER:-eend} _eend eerror "$@"
        retval=$?
        LAST_E_CMD="eend"
        return "${retval}"
@@ -300,7 +300,7 @@ ewend()
 {
        local retval
 
-       _eend ewarn "$@"
+       CALLER=${CALLER:-ewend} _eend ewarn "$@"
        retval=$?
        LAST_E_CMD="ewend"
        return "${retval}"
@@ -345,7 +345,7 @@ vebegin()
 veend()
 {
        if yesno "${EINFO_VERBOSE}"; then
-               eend "$@"
+               CALLER=veend eend "$@"
        elif [ "$#" -gt 0 ] && { ! is_int "$1" || [ "$1" -lt 0 ]; }; then
                printf 'Invalid argument given to veend (the exit status code 
must be an integer >= 0)\n' >&2
        else
@@ -356,7 +356,7 @@ veend()
 vewend()
 {
        if yesno "${EINFO_VERBOSE}"; then
-               ewend "$@"
+               CALLER=vewend ewend "$@"
        elif [ "$#" -gt 0 ] && { ! is_int "$1" || [ "$1" -lt 0 ]; }; then
                printf 'Invalid argument given to vewend (the exit status code 
must be an integer >= 0)\n' >&2
        else

Reply via email to