Skip to content

fix: Load MX before instantiating the error mock controller - #561

Merged
hellopablo merged 1 commit into
feature/pre-new-adminfrom
fix/errorhandler-mx-controller-early-bootstrap
Sep 8, 2026
Merged

fix: Load MX before instantiating the error mock controller#561
hellopablo merged 1 commit into
feature/pre-new-adminfrom
fix/errorhandler-mx-controller-early-bootstrap

Conversation

@hellopablo

Copy link
Copy Markdown
Member

Problem

Early exceptions (before CodeIgniter's Router loads) can cascade into a second fatal when rendering the error view:

Class "MX_Controller" not found in vendor/nails/common/src/Common/Controller/Base.php:48

Seen in production against probe URLs with disallowed URI characters (e.g. /computer/(master)/script). URI filtering runs before the MX Router, so MX/Modules.php has not registered the MX_* autoloader. NailsMockControllerApp\Controller\BaseNails\Common\Controller\Base extends MX_Controller then fatals.

Cause

ErrorHandler::instantiateMockController() loads CI_Controller, Security, Input, and Lang, then instantiates NailsMockController. It does not load Modular Extensions. MX_Controller is normally autoloaded via MX/Modules.php, which is only required from the MX Router.

Fix

  • Require MX/Modules.php when MX_Controller is not already loaded, so the MX autoloader is in place before the mock controller is constructed.
  • Wrap instantiateMockController() in try/catch (\Throwable) and fall back to halt() so a mock-controller failure never becomes an uncaught fatal.

Does not change URI filtering: production still halt()s disallowed characters as 404; non-prod still bubbles.

Follow-up

Error views can be rendered before the MX Router registers the MX_*
autoloader (e.g. URI character filtering). Nails\Common\Controller\Base
extends MX_Controller, so skip that load and error rendering fatals.
Fall back to halt() if the mock controller still cannot be created.
@hellopablo
hellopablo merged commit 62cc367 into feature/pre-new-admin Sep 8, 2026
4 checks passed
@hellopablo
hellopablo deleted the fix/errorhandler-mx-controller-early-bootstrap branch September 8, 2026 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant