Closed lsh-0 closed 2 years ago
Ah, interesting. So the ExtensionDownloadCommand
(and a bunch of other cv
subcommands) does check for a bunch of error-conditions and exits with non-zero for those, but the error above is a bit different. In that case, cv
calls the civicrm-core
bootstrap logic. That bootstrap logic doesn't report errors in a pretty way -- by default it calls an older PEAR fatal-error-handler (designed for web-based consumers).
There is a protocol for swapping the PEAR fatal-error-handler and using Exception
s instead (e.g. CRM_Core_TemporaryErrorScope::useException()
). Exception
s are nice because they bubble up in a way that cv
(Symfony Console) can catch the error and report it nicely. But the protocol assumes that you've already booted!
What we probably need is a patch to https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/Error.php with another protocol for opting into Exception
-based errors before bootstrap. (Ex: define('CIVICRM_DEFAULT_ERROR','exception');
)
I'm not a php/civi/drupal developer, I just need to get a growing list of civi extensions installed in an automated fashion.
I'm happy to provide any version details and test any solutions but can't contribute any code. Sorry
When outputting the error page, CiviCRM also doesn't give a proper HTTP status code :/ This could result in e.g. a webhook not retrying.
Visiting /sites/all/modules/civicrm/extern/soap.php without database outputs Initialization Error with status 200. Running cv ext:upgrade-db
gives you the same Initialization Error with exit code 0.
I believe the edge-case above was eventually resolved:
[bknix-max:~/bknix/build/dmaster/web/sites/all/modules/civicrm] cv ev -v 'echo 123;' ; echo "exit=[$?]"
<p>Initialization Error</p><p><pre>Array
(
[callback] => Array
(
[0] => CRM_Core_Error
[1] => simpleHandler
)
[code] => -24
[message] => DB Error: connect failed
[mode] => 16
[debug_info] => [nativecode=Unknown database 'dmastercivi_pa1rx']
[type] => DB_Error
[user_info] => [nativecode=Unknown database 'dmastercivi_pa1rx']
[to_string] => [db_error: message="DB Error: connect failed" code=-24 mode=callback callback=CRM_Core_Error::simpleHandler prefix="" info=" [nativecode=Unknown database 'dmastercivi_pa1rx']"]
)
</pre></p><p></p><p>Initialization Error</p><p><pre>Array
(
[callback] => Array
(
[0] => CRM_Core_Error
[1] => simpleHandler
)
[code] => -24
[message] => DB Error: connect failed
[mode] => 16
[debug_info] => [nativecode=Unknown database 'dmastercivi_pa1rx']
[type] => DB_Error
[user_info] => [nativecode=Unknown database 'dmastercivi_pa1rx']
[to_string] => [db_error: message="DB Error: connect failed" code=-24 mode=callback callback=CRM_Core_Error::simpleHandler prefix="" info=" [nativecode=Unknown database 'dmastercivi_pa1rx']"]
)
</pre></p><p></p>
exit=[255]
I'm not exactly sure when that was fixed. It could've been the extra shutdown function (2ba941e4164e6a8bd915be0c08877ba805be1bc4), or it could've been an improvement in civicrm-core
s error-reporting during bootstrap.
On the tangential point about core and HTTP exit codes, I would note improved coverage from tests like:
in this example the civi database doesn't exist:
I would expect something other than
0
(success).