Duplicate CLI Add-on Install Proceeds to Import after Exception

pegasus

Well-known member
Affected version
2.0.7
The CLI variation of add-on:install does the following:
  1. Run the install method(s) of the add-on's setup class
  2. Run add-on:import
  3. Run add-on:post-install
If the setup class's install method throws an exception, the exception is printed to the terminal as expected. However, the process is not terminated. Step 1 is aborted, but steps 2 and 3 proceed normally. This is problematic when step 1 is supposed to make database changes, step 2 adds class extensions/listeners that expect those changes to have been successful, and step 3 activates said listeners (which I imagine is a common setup design).

This can leave a forum in an unusable state, until class-extensions and code-event listeners are disabled via XenForo's config.php and the add-on is removed manually.

If any step in the install/upgrade of an add-on fails with an exception, then the entire CLI script should abort, not proceed to the next step.

Easy enough to reproduce. Create an add-on with at least 1 XML item that will be imported. Create a setup class with an install method of only line which throws an exception. The exception will be thrown but the XML items will be imported and built anyway.

The problem appears to be that XF\Error::displayFatalExceptionMessage does not set the status code to 255. After adding exit(255) to the end of that method, the CLI action aborts as expected.
 
Last edited:
This should be resolved in the next release. See:
 
Thanks, in the release notes, you may want to warn users not to use CLI install/upgrade in earlier versions, since the bug can leave the forum in an unusable state.
 
Top Bottom