code: def _raise_last_error(bulk_write_result):
      
      # Prefer write errors over write concern errors
      write_errors = bulk_write_result.get("writeErrors")
      if write_errors:
          _raise_last_write_error(write_errors)
  
      _raise_write_concern_error(bulk_write_result["writeConcernErrors"][-1])
docs: Backward compatibility helper for insert error handling.