docs: def report_error(title=None, data={}, caught=None, is_fatal=False):
      """Format a crash report and send it somewhere relevant. There are two
      types of crashes: fatal crashes (backend errors) or non-fatal ones (just
      reporting a glitch, but the api call did not fail)"""
  
      # Don't report errors if NO_ERROR_REPORTING set to 1 (set by run_acceptance_tests)
      if os.environ.get('DO_REPORT_ERROR', None):
          # Force error reporting
          pass
      elif os.environ.get('NO_ERROR_REPORTING', '') == '1':
          log.info("NO_ERROR_REPORTING is set: not reporting error!")
          return
      elif 'is_ec2_instance' in data:
          if not data['is_ec2_instance']:
              # Not running on amazon: no reporting
              log.info("DATA[is_ec2_instance] is False: not reporting error!")
              return
      elif not is_ec2_instance():
          log.info("Not running on an EC2 instance: not reporting error!")
          return
  
      # Fill error report with tons of usefull data
      if 'user' not in data:
          populate_error_report(data)
  
      # Add the message
      data['title'] = title
      data['is_fatal_error'] = is_fatal
  
      # Add the error caught, if any:
      if caught:
          data['error_caught'] = "%s" % caught
  
      # Add a trace - Formatting traceback may raise a UnicodeDecodeError...
      data['stack'] = []
      try:
          data['stack'] = [l for l in traceback.format_stack()]
      except Exception:
          data['stack'] = 'Skipped trace - contained non-ascii chars'
  
      # inspect may raise a UnicodeDecodeError...
      fname = ''
      try:
          fname = inspect.stack()[1][3]
      except Exception as e:
          fname = 'unknown-method'
  
      # Format the error's title
      status, code = 'unknown_status', 'unknown_error_code'
      if 'response' in data:
          status = data['response'].get('status', status)
          code = data['response'].get('error_code', code)
          title_details = "%s %s %s" % (ApiPool().current_server_name, status, code)
      else:
          title_details = "%s %s()" % (ApiPool().current_server_name, fname)
  
      if is_fatal:
          title_details = 'FATAL ERROR %s' % title_details
      else:
          title_details = 'NON-FATAL ERROR %s' % title_details
  
      if title:
          title = "%s: %s" % (title_details, title)
      else:
          title = title_details
  
      global error_reporter
      log.info("Reporting crash...")
  
      try:
          error_reporter(title, json.dumps(data, sort_keys=True, indent=4))
      except Exception as e:
          # Don't block on replying to api caller
          log.error("Failed to send email report: %s" % str(e))