commit: 66d65856ae58371dc9285b3bef0b6567abfe3c5e
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Thu Aug 11 23:50:01 2022 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Jun 1 21:41:59 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=66d65856
isolated-functions.sh: have __helpers_die() propagate $? if non-zero
Up until now, __helpers_die() would return the status value of echo in
the case that nonfatal is in effect. I would aver that it is not
sensible for it to do so. Instead, have it unconditionally return a
non-zero value, thus propagating a failure state. That makes it possible
to write code such as:
__my_helper() {
if ! something_else; then
__helpers_die "failure message"
fi
}
If something_else succeeds, the function will return 0. Otherwise, the
function will return 1, thanks to this change. Alternatively, it could
be written as:
__my_helper() {
something_else || __helpers_die "failure message"
}
The second way is better in so far as __helpers_die() will be able to
capture the precise return value of "something_else" and propagate it.
Thus, the sample __my_helper() function would then be guaranteed to
return that very same value.
Before deciding to commit this, I audited all instances in which
__helpers_die() is invoked and determined that there will be no
behavioural changes, with just one exception: bin/ecompress-file will
now return non-zero in the case that __helpers_die() is invoked. I am
fairly confident that it should have been doing so to begin with.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/isolated-functions.sh | 3 +++
1 file changed, 3 insertions(+)
diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh
index 7ce43541c1..73a94dac7e 100644
--- a/bin/isolated-functions.sh
+++ b/bin/isolated-functions.sh
@@ -110,10 +110,13 @@ nonfatal() {
}
__helpers_die() {
+ local retval=$?
+
if ___eapi_helpers_can_die && [[ ${PORTAGE_NONFATAL} != 1 ]]; then
die "$@"
else
echo -e "$@" >&2
+ return "$(( retval || 1 ))"
fi
}