public static function setErrorHandler(ContainerInterface $container, string $context = '') /*: void*/
    {
        set_error_handler(function($severity, $message, $file, $line) use ($container, $context) {
            if (!(error_reporting() & $severity)) {
                // Pass-thru to PHP default error handler.
                return false;
            }
            try {
                $name = 'Unknown PHP error type';
                $level = 'alert';
                $types = [
                    E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
                    E_PARSE => 'E_PARSE',
                ];
                if (isset($types[$severity])) {
                    $name = $types[$severity];
                    $level = 'error';
                }
                else {
                    $types = [
                        E_WARNING => 'E_WARNING',
                        E_CORE_WARNING => 'E_CORE_WARNING',
                        E_COMPILE_WARNING => 'E_COMPILE_WARNING',
                        E_USER_WARNING => 'E_USER_WARNING',
                    ];
                    if (isset($types[$severity])) {
                        $name = $types[$severity];
                        $level = 'warning';
                    }
                    else {
                        $types = [
                            E_NOTICE => 'E_NOTICE',
                            E_USER_NOTICE => 'E_USER_NOTICE',
                            E_STRICT => 'E_STRICT',
                            E_DEPRECATED => 'E_DEPRECATED',
                            E_USER_DEPRECATED => 'E_USER_DEPRECATED',
                        ];
                        if (isset($types[$severity])) {
                            $name = $types[$severity];
                            $level = 'notice';
                        }
                    }
                }
                $msg = rtrim(
                        $name . '(' . $severity . ')@' . $file . ':' . $line . ': '
                        . addcslashes($message, "\0..\37"),
                        '.'
                    ) . '.';
                $trace = '';
                if ($container->has('logger')) {
                    if ($container->has('inspect')) {
                        $trace = "\n" . $container->get('inspect')->trace(null, ['wrappers' => 1]);
                    }
                    $container->get('logger')->log($level, $msg . $trace);
                } else {
                    error_log($msg);
                }
                switch ($context) {
                    case 'http':
                        // Don't err/die on notice.
                        if ($level == 'notice') {
                            return true;
                        }
                        header('HTTP/1.1 500 Internal Server Error');
                        // Don't appear like PHP fatal error white-screen-of-death.
                        echo '<html><body><h1 style="font-family:sans-serif;color:darkblue">Internal Server Error</h1></body></html>';
                        exit;
                    case 'cli':
                        switch ($level) {
                            case 'warning':
                                echo "\033[01;33m[warning]\033[0m ";
                                break;
                            case 'notice':
                                echo "\033[01;36m[notice]\033[0m ";
                                break;
                            default:
                                echo "\033[01;31m[error]\033[0m ";
                        }
                        echo $msg  . (!$trace ? '' : "\n- Check log.") . "\n";
                        exit;
                    default:
                        // Don't err/die on notice.
                        if ($level == 'notice') {
                            return true;
                        }
                }
            } catch (\Throwable $ignore) {
            }
            // Pass-thru to PHP default error handler.
            return false;
        });
    }