Improve error reporting on content mismatch
Closes #3525769
Merge request reports
Activity
139 140 140 141 $this->io->write("Unpacking has updated the root composer files.", verbosity: IOInterface::VERBOSE); 141 142 142 assert(self::checkRootPackage($composer_content, $this->composer->getPackage()), 'Composer root package and composer.json match'); In which cases this code runs in production environments? When it is called by Project Browser? If that happens, should the process fail and let the user know that the unpack process finished with an invalid state and the root composer.json is not up to date?
Based on my testing, whenever this assert fails, every Composer command afterwards starts acting differently because Composer tries to resolve the problem.
Well, what I actually asked is in what conditions the Recipe Unpack plugin will run in a production environment? Project Browser is the only thing that occurs to me that could run this plugin when it will support install Recipes on the UI... otherwise, I would assume this code only runs in development environment, which case
assert()
is fine.However, if unpack will run in production envs than throwing and handling an exception could be a better alternative.
Anyway, this thread is not strictly related to the change that I proposed, considering to switch from assert() to exception could be a different issue.
139 140 140 141 $this->io->write("Unpacking has updated the root composer files.", verbosity: IOInterface::VERBOSE); 141 142 142 assert(self::checkRootPackage($composer_content, $this->composer->getPackage()), 'Composer root package and composer.json match'); 143 $diff = self::compareComposerContentWithRootPackage($composer_content, $this->composer->getPackage()); 144 assert(empty($diff), 145 sprintf("Composer root package and composer.json mismatch detected.\nrequire: %s\nrequire-dev: %s\n", 146 array_key_exists('require', $diff) ? implode(', ', $diff['require']) : 'OK', 147 array_key_exists('require-dev', $diff) ? implode(', ', $diff['require-dev']) : 'OK', 148 ) 149 ); - Comment on lines +143 to +149
changed this line in version 3 of the diff
139 140 140 141 $this->io->write("Unpacking has updated the root composer files.", verbosity: IOInterface::VERBOSE); 141 142 142 assert(self::checkRootPackage($composer_content, $this->composer->getPackage()), 'Composer root package and composer.json match'); 143 if (ini_get('zend.assertions') > 0) { @alexpott is it better this way?