0

After importing a CSV of contacts, I'm getting a blank screen with the error message below. Typically, I get a report of how many contacts were skipped due to duplicates. It appears the data is being imported though this makes me nervous to import a larger data set. Any ideas whats happening?

Warning: Illegal string offset 'code' in /home/DOMAINNAME/www/www/wp-content/plugins/civicrm/civicrm/CRM/Core/Error.php on line 1019

Warning: Cannot modify header information - headers already sent by (output started at /home/DOMAINNAME/www/www/wp-content/plugins/civicrm/civicrm/CRM/Core/Error.php:1019) in /home/DOMAINNAME/www/www/wp-content/plugins/civicrm/civicrm/CRM/Utils/System/Base.php on line 987

1 Answer 1

0

TL;DR: Warnings are signs that something's not quite right, but are also usually ignorable.

Here it looks to me like any of the following might possibly be happening:

  • There's a bug in core or in an extension or some custom code that's generating an error described by an array, where it should be using a string. It looks like the function CRM_Core_Error::isAPIError() allows the error to be either a string, or a special case for receiving errors from the API where the error var must be an array with a key of 'code' which is missing in your case, hence the error.

  • There is some debugging code in place which is generating output when it shouldn't (sometimes in development people might resort to "print 'what is going on here, then? Here is some data to help me figure it out...'" type code - this should never end up on production sites.

  • You have XDEBUG enabled and it is the version that contains a known bug whereby it outputs something such that the web server thinks that the headers are sent already, so new headers can't then be added.

This probably can't be debugged in a public forum, without the actual data and environment. You could experiment with different data sets to see if it always happens - e.g. try importing a single row of clean-looking data, does that generate the error? If so, try importing a reduced number of columns, does that still generate the error? This way you can find if there's some specific thing that's causing the problem, which will help pinpoint the real issue.

If you have the requisite skills (or, failing that, a maveric attitude), you could try editing your civicrm/CRM/Core/Error.php file around line 1017 as follows...

I assume it currently looks like:

public static function isAPIError($error, $type = CRM_Core_Error::FATAL_ERROR) {
  if (is_array($error) && !empty($error['is_error'])) {                         
    $code = $error['error_message']['code'];                                    
    if ($code == $type) {                                                       
      return TRUE;                                                              
    }                                                                           
  }                                                                             
  return FALSE;                                                                 
}                                                                               

You could replace that with

public static function isAPIError($error, $type = CRM_Core_Error::FATAL_ERROR) {
  if (is_array($error) && !empty($error['is_error'])) {                         
    $code = $error['error_message']['code'] ?? NULL;
    if ($code === NULL) {
      try { throw new \Exception(); }                                                                                
      catch (\Exception $e) {                                                                                        
        Civi::log()->error("Caught invalid error parameter: " . json_encode($error) . "\n" . $e->getTraceAsString());
      }                                                                                                              
      return FALSE;                                                                                                  
    }
    if ($code == $type) {                                                       
      return TRUE;                                                              
    }                                                                           
  }                                                                             
  return FALSE;                                                                 
}                                                                               

This will mean

  1. You won't see the error messages any more. (at least not the first one)
  2. Where the error messages would have been seen at the browser, they will now be in your CiviCRM log file, which will show exactly what the offending data was, and possibly which code is causing it. This information could be passed to a developer for further investigation.

Do note though, that editing code files is risky - can completely crash your site - so you absolutely must make a backup of the original code file before changing it and ideally you'd do this on an offline development version; ideally you'd be a developer :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.