Generic error handler function for POSIX shell scripts
I'm a big fan of tput, which many script authors seem to overlook, for generating appropriate terminal escapes.  Perhaps my enthusiasm started back in the early '90s, when using idiosyncratic (non-ANSI) terminals, but it still glows bright whenever I run a command in an Emacs buffer or output to a file.

A style point, on which you may disagree: I prefer not to enclose parameter names in braces unless it's required (for transforming the expansion, or to separate from an immediately subsequent word).  So [ &quot;$#&quot; -ne 3 ] rather than [ &quot;${#}&quot; -ne 3 ], for example.  The braces aren't wrong, but do feel unidiomatic there.

A simple improvement: you can save a lot of doubled-backslashes in the printf format strings by using single quotes rather than double quotes (this also protects you against accidentally expanding variables into the format string).  I also find it easier to match arguments to format if I make judicious use of line continuation.  Example:
    printf '%s%b()\n\n\t%s%b%s\n\nexit code = %b%s\n' \
           &quot;$bold_yellow&quot; &quot;$2&quot; \
           &quot;$nocolor&quot; &quot;$3&quot; &quot;$bold_red&quot; \
           &quot;$1&quot; &quot;$nocolor&quot; &gt;&amp;2


The definition of is_number isn't shown in your example function, but something similar is written in full here:
# check if the first argument is a number
# if not, print out an internal error without colors
if ! [ &quot;${1}&quot; -eq &quot;${1}&quot; ] 2&gt; /dev/null
then

I think it makes sense to have is_number for that test; it would certainly reduce the need for comments:
if ! is_number &quot;$1&quot;
then    # print out an internal error without colors


It probably makes sense to redirect output to the error stream once at the beginning of print_error_and_exit, since we won't be generating any ordinary output from this point onwards:
print_error_and_exit()
{
    exec &gt;&amp;2

That saves the tedium of adding a redirect to every output command, and neatly avoids the easy mistake of missing one.

When we test that tput succeeds, perhaps we should tput sgr0 without redirecting to null, so that the output device is in a known state (thus killing two birds with one stone)?
If tput works at all, then when its argument can't be converted, its output is empty, which is fine.  If we want to be really robust when tput doesn't even exist, then we could test like this:
tput sgr0 2&gt;/dev/null || alias tput=true

Then we don't need a separate branch for the non-coloured output (we'll just output empty strings in the formatting positions).  That won't quite work as I've written it, unless we specifically export the alias to sub-shells, but we can more conveniently just use a variable:
tput=tput
$tput sgr0 2&gt;/dev/null || tput=true

We might also choose to test that the output is a tty (test -t 1, if we've done the exec I suggested, else test -t 2).

$bold_yellow saves no typing compared to $bold$yellow, and it's only used once anyway, so it can easily be eliminated.  Same for $bold$red.

Modified code
Applying my suggestions, we get:
is_number()
{
    test &quot;$1&quot; -eq &quot;$1&quot; 2&gt;/dev/null
}

print_error_and_exit()
# expected arguments:
# $1 = exit code
# $2 = error origin (usually function name)
# $3 = error message
{
    # all output to error stream
    exec &gt;&amp;2

    if [ &quot;$#&quot; -ne 3 ]
    then    # wrong argument count - internal error
        printf 'print_error_and_exit() internal error\n\n\tWrong number of arguments has been passed: %b!\n\tExpected the following 3:\n\t\t\$1 - exit code\n\t\t\$2 - error origin\n\t\t\$3 - error message\n\nexit code = 1\n' \
               &quot;$#&quot;
        exit 1
    fi

    if ! is_number &quot;$1&quot;
    then    # wrong argument type - internal error
        printf 'print_error_and_exit() internal error\n\n\tThe first argument is not a number: %b!\n\tExpected an exit code from the script.\n\nexit code = 1\n' \
               &quot;$1&quot;
        exit 1
    fi

    # if tput doesn't work, then ignore
    tput=tput
    test -t 1 || tput=true
    $tput sgr0 2&gt;/dev/null || tput=true
    
    # colors definitions
    readonly bold=$($tput bold)
    readonly red=$($tput setaf 1)
    readonly yellow=$($tput setaf 3)
    readonly nocolor=$($tput sgr0)

    # highlight the error origin and the exit code
    printf '%s%b()\n\n\t%s%b%s\n\nexit code = %b%s\n' \
           &quot;${bold}$yellow&quot; &quot;$2&quot; \
           &quot;$nocolor&quot; &quot;$3&quot; &quot;${bold}$red&quot; \
           &quot;$1&quot; &quot;$nocolor&quot;

    exit &quot;$1&quot;
}