It's not a good idea to use set -e inside functions1, because it will cause one's shell to terminate on error.Therefore, in shell functions a lot of my code looks like this:[[ -e $file ]] || {    printf -- 'foo: %s does not exist\n' $file >&2    return -1}...which is not only bulky, but also ineffective beyond the first frame of funcstack.It would be great if there were an error function that would allow at least to condense the code above to something like this[[ -e $file ]] || error -1 '%s does not exist' $fileWriting such an error function for use in interpreted scripts (as opposed to functions) is not too difficult:error () {    local exitstatus=$1    shift    {        printf -- '%s: ' ${funcstack[2]}        printf -- $@        printf -- '\n'    } >&2    exit $exitstatus}...but calling this function from within other functions is a bad idea, for the same reason that set -e inside functions is a bad idea.What's needed to implement the desired error function is a way to return control to the invoking shell's top level (thereby clearing funcstack, which could be arbitrarily long at the time error gets invoked).Is there a way to do this?PS: Of course, I did try the naive way to this:error () {    local exitstatus=$1    shift    {        printf -- '%s: ' ${funcstack[2]}        printf -- $@        printf -- '\n'    } >&2    funcstack=()}...but (unsurprisingly), zsh will have none of it:error:10: read-only variable: funcstack1In this post I'll use expressions like from within a function as shorthand for from within shell functions intended for interactive use or from within scripts meant to be sourced.
How to unwind `funcstack`?
shell script;zsh