Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more error output for db error in drush #666

Open
wants to merge 1 commit into
base: 7.x-master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion drush/civicrm.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
* 3. In an arbitrary folder specified with the --include option.
*/

use Civi\Core\Exception\DBQueryException;

/**
* Implements hook_drush_command().
*
Expand Down Expand Up @@ -1605,7 +1607,12 @@ function drush_civicrm_api() {
unset($params['version']);
$result = civicrm_api4($entity, $action, $params);
}
catch (API_Exception $e) {
catch (DBQueryException $e) {
drush_set_error('CIVICRM api error', $e->getDBErrorMessage() . ' ' . $e->getUserMessage()
. (in_array('debug=1', $args, TRUE) ? "\n" . $e->getSQL() : '')
Copy link
Contributor

@demeritcowboy demeritcowboy May 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
. (in_array('debug=1', $args, TRUE) ? "\n" . $e->getSQL() : '')
. (!empty($params['debug']) ? ("\n" . $e->getSQL()) : '')

$args has already been parsed and put into params, and depending on how you specify the args it might not look like debug=1. In fact I couldn't even figure out how to use this for api4 without using the json method where it's not in args.

Also for me getSQL() returned blank, but that's not a blocker maybe it depends what the error situation is. For me I forced a db syntax error.

I also get a secondary error Undefined variable $result, but it's not because of the PR. A followup could wrap the output block below to only run if $result actually got set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@demeritcowboy then I think maybe checking debug is too complex & just add the extra output?

);
}
catch (CRM_Core_Exception $e) {
drush_set_error('CIVICRM api error', $e->getMessage());
}
break;
Expand Down