Problem/Motivation
When there are no available cores in the subscription, or the core id is not in the list of possible search core ids, a warning is thrown for passing null value to the foreach at line 152 of PreferredCodeService ([warning] foreach() argument must be of type array|object, null given inPreferredCoreService.php:152). This is not a problem for the possible cores, as the event receives an empty array for the constructor, however the getAvailableCores() method can return NULL when there is no subscription data provided (possibly when it can't connect to Acquia Cloud?)
Steps to reproduce
Proposed resolution
Update line 149 of PreferredCoreService to $available_cores = $this->getAvailableCores() ?? []; to handle cases when there is a NULL returned from getAvailableCores(). (We could change the return value to an empty array, but it could be confusing as we wouldn't know if the client could connect to Acquia Cloud, or there are just no available cores.)
Remaining tasks
User interface changes
-
API changes
-
Data model changes
-
Issue fork acquia_search-3313861
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3313861-add-null-protector
changes, plain diff MR !6
- DIT-514/refactor_to_hmac_v2
changes, plain diff MR !10
Comments
Comment #3
balintpekkerComment #4
mglamanSo I noticed this in another area of code:
This is all because of:
I honestly don't think we even hit the
emptycheck. So instead of returningnullwe fix the function to always return an array and kill anygetAvailableCores() ?? []Comment #5
balintpekkerThat is actually my proposed resolution in the parenthesis, I just didn't want to do it without any maintainer approval, because I wasn't sure how they want to handle it (just like the comment says, do they want to throw an Exception?). But I feel like we could return an empty array there too.
Comment #6
mglamanLet's do the empty array return and fix the method.
Comment #7
balintpekkerComment #8
mglamanOne more nit
Comment #9
balintpekkerComment #11
mglamanThanks!