Handle template errors.

@return bool
492238
public function handleError($code, $message, $file = '', $line = 0, $context = array())
    {
        if ($file == 'tmpl://com:base.template.stack' || $code == 1) {
            if ($file == 'tmpl://com:base.template.stack') {
                $file = $this->getPath();
            }

            if (ini_get('display_errors')) {
                echo '<strong>'.$code.'</strong>: '.$message.' in <strong>'.$file.'</strong> on line <strong>'.$line.'</strong>';
            }

            if (ini_get('log_errors')) {
                error_log(sprintf('PHP %s:  %s in %s on line %d', $code, $message, $file, $line));
            }

            return true;
        }

        return false;
    }
773730
public function handleFatalError()
    {
        unset($this->_memoryReserve);
        
        $error = error_get_last();
        
        if (static::isFatalError($error)) {
            $exception = new ErrorException($error['message'], $error['type'], $error['type'], $error['file'], $error['line']);
            $this->exception = $exception;

            $this->logException($exception);
            
            /*
            if ($this->options['discard_output']) {
                $this->clearOutput();
            }
            
            $this->renderException($exception);
            */
            //debug_print_backtrace();
            
            exit(1);
        }
    }
101058
private function phpErrorHandler(): Closure
    {
        return static function (int $errno, string $errstr, string $errfile, int $errline): bool {
            // Ignore errors that are silenced with '@'
            if (error_reporting() & $errno) {
                throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
            }

            return true;
        };
    }
934498
public function handleChecks()
    {
        $errors = [];
        foreach ($this->_config['checks'] as $name => $check) {
            if (empty($check)) {
                continue;
            }
            $result = $check['callback']();
            if ($result !== true) {
               $errors[] = $name . ': <br>' . $check['error'] . ' - ' . $result;
            }
        }
        if (!empty($errors)) {

            $this->response->statusCode(500);

            echo date('Y-m-d H:i:s') . ': ' . $this->_config['projectName'] . ' - ' . $this->_config['serverDescription'] . ' - Status Code: ' . $this->response->statusCode() . '<br><br> ';
            foreach ($errors as $error) {
                echo $error . '<br><br>';
            }
            die;
        }
        $this->_config['onSuccess']();
        die;
    }
806764
public function handle() {
		if (\Skeleton\Core\Hook::exists('handle_error', [$this->exception])) {
			// If the error is handled within the application, no need to continue
			// internally.
			$this->last_handler = true;
			\Skeleton\Core\Hook::call('handle_error', [$this->exception]);
		}
	}
1182862
public function validateTemplate()
    {
        $templates = $this->templates;
        if (!isset($templates[$this->template])) {
            $this->addError('template', 'Invalid template selection.');
        } else {
            $templatePath = $this->templates[$this->template];
            foreach ($this->requiredTemplates() as $template) {
                if (!is_file(Yii::getAlias($templatePath . '/' . $template))) {
                    $this->addError('template', "Unable to find the required code template file '$template'.");
                }
            }
        }
    }
588829
protected function HandleError()
    {
        static $bErrorsHandled = false;
        if (!$bErrorsHandled) {
            $bErrorsHandled = true;
            $oMessageManager = TCMSMessageManager::GetInstance();
            $oGlobal = TGlobal::instance();
            $aErrorFields = $this->GetErrorFields();
            $aReturnedParameter = $oGlobal->GetUserData();
            $aTrackedErrors = array();
            $sConsumerName = self::MSG_MANAGER_NAME;
            foreach ($aErrorFields as $sErrorField) {
                if (array_key_exists($sErrorField, $aReturnedParameter) && $aReturnedParameter[$sErrorField] > 0) {
                    if (!in_array($aReturnedParameter[$sErrorField], $aTrackedErrors)) {
                        TTools::WriteLogEntry('OGONE Alias Gateway: error from alias gateway call: '.$sErrorField.'-'.$aReturnedParameter[$sErrorField], 1, __FILE__, __LINE__);
                        $oMessageManager->AddMessage($sConsumerName, 'PAYMENT-HANDLER-OGONE-ALIAS-GATEWAY-ERROR-'.$sErrorField.'-'.$aReturnedParameter[$sErrorField]);
                        $aTrackedErrors[] = $aReturnedParameter[$sErrorField];
                    }
                }
            }
        }
    }
301423
public function hasError(): bool
    {
        foreach ($this->getResultSets() as $resultSet) {
            if ($resultSet->getResponse()->hasError()) {
                return true;
            }
        }

        return false;
    }
1182338
public function showErrors()
    {
        $reporting = $this->getEnvironmentConfig('ErrorReporting', false);
        if ($reporting && strtolower($reporting) == 'on') {
            return true;
        }

        return false;
    }
875700
public function handleWsError($e)
    {
        // Pawl pls
        if (strpos($e->getMessage(), 'Tried to write to closed stream') !== false) {
            return;
        }

        $this->logger->error('websocket error', ['e' => $e->getMessage()]);
        $this->emit('error', [$e, $this]);

        $this->handleWsClose(0, 'websocket error');
    }
1372167
public function resolveTemplate()
    {
        if (strpos($this->template, '*') !== false) {
            return str_replace('*', $this->getTheme(), $this->template);
        }
        return $this->template;
    }
703427
public function handle()
    {

        if ( ! $this->confirm("Are you sure you want to run the analysis tool? This tool will make modifications to the template storage.".PHP_EOL."While it is intended to clean up the template storage, it could potentially fail. [yes|no]", false))
        {
            $this->comment('Analysis aborted by user');
            return;
        }

        $this->info('Starting analysis of template store...');
        $this->line('Store located at ' . $this->templateStorageEngine->getStoragePath());
        $vendors      = $this->templateStorageEngine->getInstalledVendors();
        $packages     = $this->templateStorageEngine->getInstalledPackages(true);
        $packageCount = 0;
        foreach ($packages as $package) {
            $packageCount += count($package['packages']);
        }
        $this->line('Found ' . count($vendors) . ' vendors and ' . $packageCount . ' packages...');


        $this->comment(PHP_EOL . 'Searching for failed update processes...');
        $failedUpdateProcesses     = [];
        $garbagePackageDirectories = [];

        foreach ($packages as $vp) {
            foreach ($vp['packages'] as $package) {
                if (Str::endsWith($package['path'], '_{updating_in_progress}')) {
                    $garbagePackageDirectories[] = $package;
                    $this->line('Identified package as possible garbage ' . $package['path']);
                } else {
                    if ($this->files->exists($package['path'] . DIRECTORY_SEPARATOR . '_newup_update_initiated')) {
                        $failedUpdateProcesses[] = $package;
                        $this->line('Identified failed package update process ' . $package['path']);
                    }
                }
            }
        }

        $this->line('Found ' . count($failedUpdateProcesses) . ' failed update processes');
        $this->line('Found ' . count($garbagePackageDirectories) . ' update directories ready for cleanup');

        $this->comment(PHP_EOL . 'Analyzing search results...');
        $recoverablePackages    = [];
        $nonRecoverablePackages = [];

        foreach ($failedUpdateProcesses as $failedUpdate) {
            if ($this->files->exists($failedUpdate['path'] . '_{updating_in_progress}')) {
                $this->line('Identified package as recoverable '.$failedUpdate['path']);
                $recoverablePackages[] = $failedUpdate;
            } else {
                $this->line('Identified a non-recoverable package '.$failedUpdate['path']);
                $nonRecoverablePackages[] = $failedUpdate;
            }
        }

        $this->line('Found '.count($recoverablePackages).' recoverable failed update processes');
        $this->line('Found '.count($nonRecoverablePackages).' non-recoverable failed update processes');

        $this->comment(PHP_EOL.'Cleaning up non-recoverable update processes...');
        if (count($nonRecoverablePackages) > 0) {
            foreach ($nonRecoverablePackages as $nonRecoverablePackage) {
                $this->files->deleteDirectory($nonRecoverablePackage['path'], false);
                $this->line('Cleaning up directory '.$nonRecoverablePackage['path']);
            }
        } else {
            $this->line('Nothing to clean up');
        }


        $this->comment(PHP_EOL.'Cleaning up failed update processes...');
        if (count($garbagePackageDirectories) > 0 ) {
            foreach ($garbagePackageDirectories as $garbage) {
                $originalPackagePath = $garbage['path'];
                $originalPackagePath = str_replace('_{updating_in_progress}', '', $originalPackagePath);

                if ($this->files->exists($originalPackagePath)) {
                    if ($this->files->exists($originalPackagePath.DIRECTORY_SEPARATOR.'_newup_update_initiated')) {
                        $this->comment('Recovering failed update process for '.$originalPackagePath);
                        $this->line('Removing failed update files at '.$originalPackagePath);
                        $this->files->deleteDirectory($originalPackagePath);
                        $this->line('Recovering files...');
                        $this->files->copyDirectory($garbage['path'], $originalPackagePath);
                        if ($this->files->exists($originalPackagePath)) {
                            $this->info('Recovered files at '.$originalPackagePath);
                        } else {
                            $this->error('Could not recover files at '.$originalPackagePath);
                        }
                        $this->line('Cleaning up garbage files at '.$garbage['path']);
                        $this->files->deleteDirectory($garbage['path']);
                    } else {
                        // Original package path does not exist, remove trash.
                        $this->line('Removing garbage '.$garbage['path'].' because '.$originalPackagePath.' no longer exists');
                        $this->files->deleteDirectory($garbage['path']);
                    }
                } else {
                    // Original package path does not exist, remove trash.
                    $this->line('Removing garbage '.$garbage['path'].' because '.$originalPackagePath.' no longer exists');
                    $this->files->deleteDirectory($garbage['path']);
                }
            }
        } else {
            $this->line('Nothing to clean up');
        }

        $this->comment(PHP_EOL.'Analysis complete');

    }
890155
public function handleException( \Throwable $e ) : bool
    {
        // Render exception
        $output = $this->renderer->output( $e );
    
        // output
        fwrite(STDERR, $output . PHP_EOL);
    
        return true;
    }
609632
public function onDeleteTemplates()
    {
        $this->validateRequestTheme();

        $type = Request::input('type');
        $templates = Request::input('template');
        $error = null;
        $deleted = [];

        try {
            foreach ($templates as $path => $selected) {
                if ($selected) {
                    $this->loadTemplate($type, $path)->delete();
                    $deleted[] = $path;
                }
            }
        }
        catch (Exception $ex) {
            $error = $ex->getMessage();
        }

        /**
         * @event cms.template.delete
         * Fires after a CMS template (page|partial|layout|content|asset) has been deleted.
         *
         * Example usage:
         *
         *     Event::listen('cms.template.delete', function ((\Cms\Controllers\Index) $controller, (string) $type) {
         *         \Log::info("A $type has been deleted");
         *     });
         *
         * Or
         *
         *     $CmsIndexController->bindEvent('template.delete', function ((string) $type) {
         *         \Log::info("A $type has been deleted");
         *     });
         *
         */
        $this->fireSystemEvent('cms.template.delete', [$type]);

        return [
            'deleted' => $deleted,
            'error'   => $error,
            'theme'   => Request::input('theme')
        ];
    }
755473
function error() {
        if ($this->error) {
            //Put some template variables for debugging here ...
            $debug_tpl_vars = array(
                '{LANGUAGE}' => $this->language,
                '{PATH}' => $this->language_path
            );
            $msg = str_replace(
                array_keys($debug_tpl_vars),
                array_values($debug_tpl_vars),
                $this->error_messages[$this->error]);

            return "<br /><strong>GeSHi Error:</strong> $msg (code {$this->error})<br />";
        }
        return false;
    }
103161
protected function handle_error($query)
    {
        $error = $this->dbh->errorInfo();

        if (empty($this->options['ignore_key_errors']) || !in_array($error[0], array('23000', '23505'))) {
            $this->db_error = true;
            $this->db_error_msg = sprintf('[%s] %s', $error[1], $error[2]);

            if (empty($this->options['ignore_errors'])) {
                rcube::raise_error(array(
                        'code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__,
                        'message' => $this->db_error_msg . " (SQL Query: $query)"
                    ), true, false);
            }
        }

        return false;
    }
624187
private function validRequest()
    {
        // Is a path and template set
        if (empty($this->template) || empty($this->path)) {
            return false;
        }

        // Is the template a valid template
        if (!array_key_exists($this->template, $this->templates)) {
            return false;
        }

        return true;
    }