Skip Navigation

[Resolved] Types – Critical Error due to failing to checking settings is an array

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 3 replies, has 1 voice.

Last updated by Minesh 1 week, 4 days ago.

Assisted by: Minesh.

Author
Posts
#2808212

We recently had to patch you plugin due to a warning that only happens on the wp-admin screen yet it was creating a fatal error. We are running the most recent version of the plugins. You failed to checking settings is an array.

//php warnings from logs
Warning: Invalid argument supplied for foreach() in /code/web/wp-content/plugins/types/vendor/otgs/installer/includes/class-wp-installer.php on line 773
Warning: Invalid argument supplied for foreach() in /code/web/wp-content/plugins/types/vendor/otgs/installer/includes/repository/class-otgs-installer-repositories.php on line 29
Fatal error: Uncaught TypeError: Argument 2 passed to OTGS_Installer_Plugin_Finder::__construct() must be of the type array, null given, called in /code/web/wp-content/plugins/types/vendor/otgs/installer/includes/class-otgs-installer-factory.php on line 235 and defined in /code/web/wp-content/plugins/types/vendor/otgs/installer/includes/class-otgs-installer-plugin-finder.php:17
Stack trace:
#0 /code/web/wp-content/plugins/types/vendor/otgs/installer/includes/class-otgs-installer-factory.php(235): OTGS_Installer_Plugin_Finder->__construct(Object(OTGS_Installer_Plugin_Factory), NULL)
#1 /code/web/wp-content/plugins/types/vendor/otgs/installer/includes/class-otgs-installer-factory.php(247): OTGS_Installer_Factory->get_plugin_finder()
#2 /code/web/wp-content/plugins/types/vendor/otgs/installer/includes/class-otgs-installer-factory.php(258): OTGS_Installer_Factory->create_upgrade_response()
#3 /code/web/wp-content/plugins/types/vendor/otgs/installer/includes/class-otgs-installer-loader.php(25): OTGS_Installer_Factory->load_upg in /code/web/wp-content/plugins/types/vendor/otgs/installer/includes/class-otgs-installer-plugin-finder.php on line 17
Error: There has been a critical error on this website.Learn more about troubleshooting WordPress. There has been a critical error on this website.

///More info
The error indicates that the OTGS_Installer_Plugin_Finder class is being instantiated with a null value for the second argument, which is expected to be an array. This issue likely from the get_plugin_finder() method in the OTGS_Installer_Factory class, where $settings['repositories'] is being passed but is null.

We fix this by checking to ensure $settings['repositories'] is an array before passing it to the OTGS_Installer_Plugin_Finder constructor. If it's not an array, we can default it to an empty array.

Recommended fix - which we patched on our envs, but would love to have this updated into the plugin. Please review

File: class-otgs-installer-factory.php line 231-239

public function get_plugin_finder() {
if ( ! $this->plugin_finder ) {
- $settings = $this->get_installer()->get_settings();
- $this->plugin_finder = new OTGS_Installer_Plugin_Finder( $this->get_plugin_factory(), $settings['repositories'] );
+ $settings = $this->get_installer()->get_settings();
+ $repositories = isset($settings['repositories']) && is_array($settings['repositories']) ? $settings['repositories'] : [];
+ $this->plugin_finder = new OTGS_Installer_Plugin_Finder( $this->get_plugin_factory(), $repositories );
}

return $this->plugin_finder;

#2808279

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Glad that you shared all this required information but may I ask what are the steps that we should follow in order to reproduce the issue.

#2808647

It's best practice to set $settings['repositories'] is an array before passing it to the OTGS_Installer_Plugin_Finder constructor. I think you all were having server issues last week so we were getting errors since your server was having issues and unable to check. Please pass on to your engineers to review the code suggestion.

#2808762

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - I've passed all the required information in front of our next level support and they will check and try to add the fix with next release.