diff --git a/src/Common/Service/ErrorHandler.php b/src/Common/Service/ErrorHandler.php index 3f579213..b7f4826c 100644 --- a/src/Common/Service/ErrorHandler.php +++ b/src/Common/Service/ErrorHandler.php @@ -497,7 +497,16 @@ public static function renderErrorView( ); } - static::instantiateMockController(); + try { + static::instantiateMockController(); + } catch (\Throwable $e) { + static::halt( + ArrayHelper::get('sMessage', $aData) ?: $e->getMessage(), + ArrayHelper::get('sSubject', $aData), + $iCode, + $aTrace + ); + } // Flush the output buffer if ($bFlushBuffer) { @@ -670,6 +679,14 @@ protected static function instantiateMockController() require_once BASEPATH . 'core/Controller.php'; + // URI filtering (and other early failures) can occur before the MX + // Router is loaded. Nails\Common\Controller\Base extends MX_Controller, + // so the mock controller used to render error views must ensure MX is + // available. Modules.php registers the MX_* autoloader. + if (!class_exists('MX_Controller', false)) { + require_once Config::get('NAILS_COMMON_PATH') . 'MX/Modules.php'; + } + // Match pocketarc/codeigniter system/core/CodeIgniter.php: // Security requires $charset; Input requires the Security instance. $sCharset = strtoupper((string) config_item('charset'));