Replace LOG_AND_RETURN_ERROR with "return LOG_ERROR"

Deletes the LOG_AND_RETURN_ERROR and LOG_AND_RETURN_ERROR_EX macros.
This makes for code that is easier to read.

Bug: None
Change-Id: I9ce0de3c2f6337def0ae8a3d626fd3374d4bebe0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/459600
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#47240}
diff --git a/api/rtc_error.h b/api/rtc_error.h
index ffc2b17..a0a19ae 100644
--- a/api/rtc_error.h
+++ b/api/rtc_error.h
@@ -225,20 +225,6 @@
   std::optional<uint16_t> sctp_cause_code_;
 };
 
-// Helper macro that can be used by implementations to create an error with a
-// message and log it. `message` should be a string literal or movable
-// std::string.
-#define LOG_AND_RETURN_ERROR_EX(type, message, severity)                     \
-  {                                                                          \
-    RTC_DCHECK(type != RTCErrorType::NONE);                                  \
-    RTC_LOG(severity) << message << " (" << ::webrtc::ToString(type) << ")"; \
-    return ::webrtc::RTCError(type, message);                                \
-  }
-
-// LOG_AND_RETURN_ERROR is a s simpler variant of `LOG_AND_RETURN_ERROR_EX`.
-#define LOG_AND_RETURN_ERROR(type, message) \
-  LOG_AND_RETURN_ERROR_EX(type, message, LS_ERROR)
-
 inline RTCError LogErrorImpl(RTCError error,
                              LoggingSeverity severity,
                              const char* file,
@@ -255,7 +241,6 @@
   return error;
 }
 
-// A slightly more C++ looking alternative to the LOG_AND_RETURN_ERROR() macro.
 // This approach does not hide the return statement and also allows for
 // constructing/formatting the error string inline.
 //
diff --git a/api/rtc_error_unittest.cc b/api/rtc_error_unittest.cc
index 596bc64..7527ae6 100644
--- a/api/rtc_error_unittest.cc
+++ b/api/rtc_error_unittest.cc
@@ -259,7 +259,7 @@
   EXPECT_STREQ(error.message(), "StringyBuilder #2");
 }
 
-// Tests a non macro based alternative to `LOG_AND_RETURN_ERROR`.
+// Tests `LOG_ERROR`.
 TEST(RTCErrorOrTest, BuildStringLog) {
   class LogSinkImpl : public LogSink {
    public:
diff --git a/media/base/codec_list.cc b/media/base/codec_list.cc
index c82b720..4be60c4 100644
--- a/media/base/codec_list.cc
+++ b/media/base/codec_list.cc
@@ -38,8 +38,8 @@
         RTC_LOG(LS_ERROR) << "Duplicate payload type in codec list, " << codec
                           << " and " << codecs[it->second]
                           << " have the same ID";
-        LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                             "Duplicate payload type in codec list");
+        return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                         << "Duplicate payload type in codec list");
       }
     }
   }
@@ -74,8 +74,8 @@
         if (!(FromString(apt_it->second, &associated_pt))) {
           RTC_LOG(LS_ERROR) << "Non-numeric argument to rtx apt: " << codec
                             << " apt=" << apt_it->second;
-          LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                               "Non-numeric argument to rtx apt parameter");
+          return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                           << "Non-numeric argument to rtx apt parameter");
         }
         if (codec.id != Codec::kIdNotSet &&
             pt_to_index.count(associated_pt) != 1) {
@@ -83,9 +83,9 @@
               << "Surprising condition: RTX codec APT not found: " << codec
               << " points to a PT that occurs "
               << pt_to_index.count(associated_pt) << " times";
-          LOG_AND_RETURN_ERROR(
-              RTCErrorType::INVALID_PARAMETER,
-              "PT pointed to by rtx apt parameter does not exist");
+          return LOG_ERROR(
+              RTCError(RTCErrorType::INVALID_PARAMETER)
+              << "PT pointed to by rtx apt parameter does not exist");
         }
         // const Codec& referred_codec = codecs[pt_to_index[associated_pt]];
         // Not true:
diff --git a/media/base/media_engine.cc b/media/base/media_engine.cc
index 78bb62a..73a8710 100644
--- a/media/base/media_engine.cc
+++ b/media/base/media_engine.cc
@@ -111,10 +111,9 @@
         }
       }
       if (!codecFound) {
-        LOG_AND_RETURN_ERROR(
-            RTCErrorType::INVALID_MODIFICATION,
-            "Attempted to use an unsupported codec for layer " +
-                std::to_string(i));
+        return LOG_ERROR(RTCError(RTCErrorType::INVALID_MODIFICATION)
+                         << "Attempted to use an unsupported codec for layer "
+                         << i);
       }
     }
     if (rtp_parameters.encodings[i].scalability_mode) {
@@ -133,10 +132,10 @@
         }
 
         if (!scalabilityModeFound) {
-          LOG_AND_RETURN_ERROR(
-              RTCErrorType::INVALID_MODIFICATION,
-              "Attempted to set RtpParameters scalabilityMode "
-              "to an unsupported value for the current codecs.");
+          return LOG_ERROR(
+              RTCError(RTCErrorType::INVALID_MODIFICATION)
+              << "Attempted to set RtpParameters scalabilityMode "
+                 "to an unsupported value for the current codecs.");
         }
       } else {
         bool scalabilityModeFound = false;
@@ -148,10 +147,10 @@
           }
         }
         if (!scalabilityModeFound) {
-          LOG_AND_RETURN_ERROR(
-              RTCErrorType::INVALID_MODIFICATION,
-              "Attempted to set RtpParameters scalabilityMode "
-              "to an unsupported value for the current codecs.");
+          return LOG_ERROR(
+              RTCError(RTCErrorType::INVALID_MODIFICATION)
+              << "Attempted to set RtpParameters scalabilityMode "
+                 "to an unsupported value for the current codecs.");
         }
       }
     }
@@ -167,39 +166,39 @@
   bool has_scale_resolution_down_to = false;
   for (size_t i = 0; i < rtp_parameters.encodings.size(); ++i) {
     if (rtp_parameters.encodings[i].bitrate_priority <= 0) {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE,
-                           "Attempted to set RtpParameters bitrate_priority to "
-                           "an invalid number. bitrate_priority must be > 0.");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_RANGE)
+                       << "Attempted to set RtpParameters bitrate_priority to "
+                          "an invalid number. bitrate_priority must be > 0.");
     }
     if (rtp_parameters.encodings[i].scale_resolution_down_by &&
         *rtp_parameters.encodings[i].scale_resolution_down_by < 1.0) {
-      LOG_AND_RETURN_ERROR(
-          RTCErrorType::INVALID_RANGE,
-          "Attempted to set RtpParameters scale_resolution_down_by to an "
-          "invalid value. scale_resolution_down_by must be >= 1.0");
+      return LOG_ERROR(
+          RTCError(RTCErrorType::INVALID_RANGE)
+          << "Attempted to set RtpParameters scale_resolution_down_by to an "
+             "invalid value. scale_resolution_down_by must be >= 1.0");
     }
     if (rtp_parameters.encodings[i].max_framerate &&
         *rtp_parameters.encodings[i].max_framerate < 0.0) {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE,
-                           "Attempted to set RtpParameters max_framerate to an "
-                           "invalid value. max_framerate must be >= 0.0");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_RANGE)
+                       << "Attempted to set RtpParameters max_framerate to an "
+                          "invalid value. max_framerate must be >= 0.0");
     }
     if (rtp_parameters.encodings[i].min_bitrate_bps &&
         rtp_parameters.encodings[i].max_bitrate_bps) {
       if (*rtp_parameters.encodings[i].max_bitrate_bps <
           *rtp_parameters.encodings[i].min_bitrate_bps) {
-        LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE,
-                             "Attempted to set RtpParameters min bitrate "
-                             "larger than max bitrate.");
+        return LOG_ERROR(RTCError(RTCErrorType::INVALID_RANGE)
+                         << "Attempted to set RtpParameters min bitrate "
+                            "larger than max bitrate.");
       }
     }
     if (rtp_parameters.encodings[i].num_temporal_layers) {
       if (*rtp_parameters.encodings[i].num_temporal_layers < 1 ||
           *rtp_parameters.encodings[i].num_temporal_layers >
               kMaxTemporalStreams) {
-        LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE,
-                             "Attempted to set RtpParameters "
-                             "num_temporal_layers to an invalid number.");
+        return LOG_ERROR(RTCError(RTCErrorType::INVALID_RANGE)
+                         << "Attempted to set RtpParameters "
+                            "num_temporal_layers to an invalid number.");
       }
     }
 
@@ -207,32 +206,32 @@
       has_scale_resolution_down_to = true;
       if (rtp_parameters.encodings[i].scale_resolution_down_to->width <= 0 ||
           rtp_parameters.encodings[i].scale_resolution_down_to->height <= 0) {
-        LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_MODIFICATION,
-                             "The resolution dimensions must be positive.");
+        return LOG_ERROR(RTCError(RTCErrorType::INVALID_MODIFICATION)
+                         << "The resolution dimensions must be positive.");
       }
     }
 
     if (!field_trials.IsEnabled("WebRTC-MixedCodecSimulcast")) {
       if (i > 0 && rtp_parameters.encodings[i - 1].codec !=
                        rtp_parameters.encodings[i].codec) {
-        LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION,
-                             "Attempted to use different codec values for "
-                             "different encodings.");
+        return LOG_ERROR(RTCError(RTCErrorType::UNSUPPORTED_OPERATION)
+                         << "Attempted to use different codec values for "
+                            "different encodings.");
       }
     }
 
     if (rtp_parameters.encodings[i].csrcs.has_value() &&
         rtp_parameters.encodings[i].csrcs.value().size() > kRtpCsrcSize) {
-      LOG_AND_RETURN_ERROR(
-          RTCErrorType::INVALID_RANGE,
-          "Attempted to set more than the maximum allowed number of CSRCs.")
+      return LOG_ERROR(
+          RTCError(RTCErrorType::INVALID_RANGE)
+          << "Attempted to set more than the maximum allowed number of CSRCs.");
     }
 
     if (i > 0 && rtp_parameters.encodings[i - 1].csrcs !=
                      rtp_parameters.encodings[i].csrcs) {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_MODIFICATION,
-                           "Attempted to set different CSRCs for different "
-                           "encodings.");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_MODIFICATION)
+                       << "Attempted to set different CSRCs for different "
+                          "encodings.");
     }
   }
 
@@ -242,9 +241,9 @@
                        return encoding.active &&
                               !encoding.scale_resolution_down_to.has_value();
                      })) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_MODIFICATION,
-                         "If a resolution is specified on any encoding then "
-                         "it must be specified on all encodings.");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_MODIFICATION)
+                     << "If a resolution is specified on any encoding then "
+                        "it must be specified on all encodings.");
   }
 
   // In a mixed codec scenario, we only support scalability modes without
@@ -258,10 +257,10 @@
       auto num_spatial_layers =
           ScalabilityModeStringToNumSpatialLayers(*scalability_mode);
       if (num_spatial_layers && *num_spatial_layers > 1) {
-        LOG_AND_RETURN_ERROR(
-            RTCErrorType::UNSUPPORTED_OPERATION,
-            "Attempted to use a scalabilityMode with spatial layers in "
-            "a mixed codec scenario.");
+        return LOG_ERROR(
+            RTCError(RTCErrorType::UNSUPPORTED_OPERATION)
+            << "Attempted to use a scalabilityMode with spatial layers in "
+               "a mixed codec scenario.");
       }
     }
   }
@@ -284,36 +283,36 @@
     std::optional<Codec> send_codec,
     const FieldTrialsView& field_trials) {
   if (rtp_parameters.encodings.size() != old_rtp_parameters.encodings.size()) {
-    LOG_AND_RETURN_ERROR(
-        RTCErrorType::INVALID_MODIFICATION,
-        "Attempted to set RtpParameters with different encoding count");
+    return LOG_ERROR(
+        RTCError(RTCErrorType::INVALID_MODIFICATION)
+        << "Attempted to set RtpParameters with different encoding count");
   }
   if (rtp_parameters.rtcp != old_rtp_parameters.rtcp) {
-    LOG_AND_RETURN_ERROR(
-        RTCErrorType::INVALID_MODIFICATION,
-        "Attempted to set RtpParameters with modified RTCP parameters");
+    return LOG_ERROR(
+        RTCError(RTCErrorType::INVALID_MODIFICATION)
+        << "Attempted to set RtpParameters with modified RTCP parameters");
   }
   if (rtp_parameters.header_extensions !=
       old_rtp_parameters.header_extensions) {
-    LOG_AND_RETURN_ERROR(
-        RTCErrorType::INVALID_MODIFICATION,
-        "Attempted to set RtpParameters with modified header extensions");
+    return LOG_ERROR(
+        RTCError(RTCErrorType::INVALID_MODIFICATION)
+        << "Attempted to set RtpParameters with modified header extensions");
   }
   if (!absl::c_equal(old_rtp_parameters.encodings, rtp_parameters.encodings,
                      [](const RtpEncodingParameters& encoding1,
                         const RtpEncodingParameters& encoding2) {
                        return encoding1.rid == encoding2.rid;
                      })) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_MODIFICATION,
-                         "Attempted to change RID values in the encodings.");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_MODIFICATION)
+                     << "Attempted to change RID values in the encodings.");
   }
   if (!absl::c_equal(old_rtp_parameters.encodings, rtp_parameters.encodings,
                      [](const RtpEncodingParameters& encoding1,
                         const RtpEncodingParameters& encoding2) {
                        return encoding1.ssrc == encoding2.ssrc;
                      })) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_MODIFICATION,
-                         "Attempted to set RtpParameters with modified SSRC");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_MODIFICATION)
+                     << "Attempted to set RtpParameters with modified SSRC");
   }
 
   return CheckRtpParametersValues(rtp_parameters, send_codecs, send_codec,
diff --git a/pc/codec_vendor.cc b/pc/codec_vendor.cc
index 50f3ef8..2adc3a6 100644
--- a/pc/codec_vendor.cc
+++ b/pc/codec_vendor.cc
@@ -660,10 +660,10 @@
         if (!IsMediaContentOfType(current_content,
                                   media_description_options.type)) {
           // Can happen if the remote side re-uses a MID while recycling.
-          LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
-                               "Media type for content with mid='" +
-                                   current_content->mid() +
-                                   "' does not match previous type.");
+          return LOG_ERROR(RTCError(RTCErrorType::INTERNAL_ERROR)
+                           << "Media type for content with mid='"
+                           << current_content->mid()
+                           << "' does not match previous type.");
         }
         const MediaContentDescription* mcd =
             current_content->media_description();
@@ -796,10 +796,10 @@
         if (!IsMediaContentOfType(current_content,
                                   media_description_options.type)) {
           // Can happen if the remote side re-uses a MID while recycling.
-          LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
-                               "Media type for content with mid='" +
-                                   current_content->mid() +
-                                   "' does not match previous type.");
+          return LOG_ERROR(RTCError(RTCErrorType::INTERNAL_ERROR)
+                           << "Media type for content with mid='"
+                           << current_content->mid()
+                           << "' does not match previous type.");
         }
         const MediaContentDescription* mcd =
             current_content->media_description();
diff --git a/pc/ice_server_parsing.cc b/pc/ice_server_parsing.cc
index b83cc86..e2b8726 100644
--- a/pc/ice_server_parsing.cc
+++ b/pc/ice_server_parsing.cc
@@ -194,22 +194,21 @@
   if (tokens.size() == kTurnTransportTokensNum) {  // ?transport= is present.
     std::vector<absl::string_view> transport_tokens = split(tokens[1], '=');
     if (transport_tokens[0] != kTransport) {
-      LOG_AND_RETURN_ERROR(
-          RTCErrorType::SYNTAX_ERROR,
-          "ICE server parsing failed: Invalid transport parameter key.");
+      return LOG_ERROR(
+          RTCError(RTCErrorType::SYNTAX_ERROR)
+          << "ICE server parsing failed: Invalid transport parameter key.");
     }
     if (transport_tokens.size() < 2) {
-      LOG_AND_RETURN_ERROR(
-          RTCErrorType::SYNTAX_ERROR,
-          "ICE server parsing failed: Transport parameter missing value.");
+      return LOG_ERROR(
+          RTCError(RTCErrorType::SYNTAX_ERROR)
+          << "ICE server parsing failed: Transport parameter missing value.");
     }
 
     std::optional<ProtocolType> proto = StringToProto(transport_tokens[1]);
     if (!proto || (*proto != PROTO_UDP && *proto != PROTO_TCP)) {
-      LOG_AND_RETURN_ERROR(
-          RTCErrorType::SYNTAX_ERROR,
-          "ICE server parsing failed: Transport parameter should "
-          "always be udp or tcp.");
+      return LOG_ERROR(RTCError(RTCErrorType::SYNTAX_ERROR)
+                       << "ICE server parsing failed: Transport parameter "
+                          "should always be udp or tcp.");
     }
     turn_transport_type = *proto;
     transport_given_explicitly = true;
@@ -219,9 +218,9 @@
       GetServiceTypeAndHostnameFromUri(uri_without_transport);
   if (service_type == ServiceType::INVALID) {
     RTC_LOG(LS_ERROR) << "Invalid transport parameter in ICE URI: " << url;
-    LOG_AND_RETURN_ERROR(
-        RTCErrorType::SYNTAX_ERROR,
-        "ICE server parsing failed: Invalid transport parameter in ICE URI");
+    return LOG_ERROR(
+        RTCError(RTCErrorType::SYNTAX_ERROR)
+        << "ICE server parsing failed: Invalid transport parameter in ICE URI");
   }
 
   // GetServiceTypeAndHostnameFromUri should never give an empty hoststring
@@ -231,9 +230,9 @@
   if ((service_type == ServiceType::STUN ||
        service_type == ServiceType::STUNS) &&
       tokens.size() > 1) {
-    LOG_AND_RETURN_ERROR(
-        RTCErrorType::SYNTAX_ERROR,
-        "ICE server parsing failed: Invalid stun url with query parameters");
+    return LOG_ERROR(
+        RTCError(RTCErrorType::SYNTAX_ERROR)
+        << "ICE server parsing failed: Invalid stun url with query parameters");
   }
 
   int default_port = kDefaultStunPort;
@@ -252,23 +251,23 @@
   if (hoststring.find('@') != absl::string_view::npos) {
     RTC_LOG(LS_ERROR) << "Invalid url with long deprecated user@host syntax: "
                       << uri_without_transport;
-    LOG_AND_RETURN_ERROR(RTCErrorType::SYNTAX_ERROR,
-                         "ICE server parsing failed: Invalid url with long "
-                         "deprecated user@host syntax");
+    return LOG_ERROR(RTCError(RTCErrorType::SYNTAX_ERROR)
+                     << "ICE server parsing failed: Invalid url with long "
+                        "deprecated user@host syntax");
   }
 
   auto [success, address, port] =
       ParseHostnameAndPortFromString(hoststring, default_port);
   if (!success) {
     RTC_LOG(LS_ERROR) << "Invalid hostname format: " << uri_without_transport;
-    LOG_AND_RETURN_ERROR(RTCErrorType::SYNTAX_ERROR,
-                         "ICE server parsing failed: Invalid hostname format");
+    return LOG_ERROR(RTCError(RTCErrorType::SYNTAX_ERROR)
+                     << "ICE server parsing failed: Invalid hostname format");
   }
 
   if (port <= 0 || port > 0xffff) {
     RTC_LOG(LS_ERROR) << "Invalid port: " << port;
-    LOG_AND_RETURN_ERROR(RTCErrorType::SYNTAX_ERROR,
-                         "ICE server parsing failed: Invalid port");
+    return LOG_ERROR(RTCError(RTCErrorType::SYNTAX_ERROR)
+                     << "ICE server parsing failed: Invalid port");
   }
 
   switch (service_type) {
@@ -281,16 +280,15 @@
       if (server.username.empty() || server.password.empty()) {
         // The WebRTC spec requires throwing an InvalidAccessError when username
         // or credential are ommitted; this is the native equivalent.
-        LOG_AND_RETURN_ERROR(
-            RTCErrorType::INVALID_PARAMETER,
-            "ICE server parsing failed: TURN server with empty "
-            "username or password");
+        return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                         << "ICE server parsing failed: TURN server with empty "
+                            "username or password");
       }
       // RFC 8489 limits the size of the STUN username field to 509 characters.
       if (server.username.size() > kMaxTurnUsernameLength) {
-        LOG_AND_RETURN_ERROR(
-            RTCErrorType::INVALID_PARAMETER,
-            "ICE server parsing failed: TURN server username is too long");
+        return LOG_ERROR(
+            RTCError(RTCErrorType::INVALID_PARAMETER)
+            << "ICE server parsing failed: TURN server username is too long");
       }
       // If the hostname field is not empty, then the server address must be
       // the resolved IP for that host, the hostname is needed later for TLS
@@ -303,11 +301,10 @@
         if (!IPFromString(address, &ip)) {
           // When hostname is set, the server address must be a
           // resolved ip address.
-          LOG_AND_RETURN_ERROR(
-              RTCErrorType::INVALID_PARAMETER,
-              "ICE server parsing failed: "
-              "IceServer has hostname field set, but URI does not "
-              "contain an IP address.");
+          return LOG_ERROR(
+              RTCError(RTCErrorType::INVALID_PARAMETER)
+              << "ICE server parsing failed: IceServer has hostname field "
+                 "set, but URI does not contain an IP address.");
         }
         socket_address.SetResolvedIP(ip);
       }
@@ -328,9 +325,8 @@
     default:
       // We shouldn't get to this point with an invalid service_type, we should
       // have returned an error already.
-      LOG_AND_RETURN_ERROR(
-          RTCErrorType::INTERNAL_ERROR,
-          "ICE server parsing failed: Unexpected service type");
+      return LOG_ERROR(RTCError(RTCErrorType::INTERNAL_ERROR)
+                       << "ICE server parsing failed: Unexpected service type");
   }
   return RTCError::OK();
 }
@@ -345,8 +341,8 @@
     if (!server.urls.empty()) {
       for (const std::string& url : server.urls) {
         if (url.empty()) {
-          LOG_AND_RETURN_ERROR(RTCErrorType::SYNTAX_ERROR,
-                               "ICE server parsing failed: Empty uri.");
+          return LOG_ERROR(RTCError(RTCErrorType::SYNTAX_ERROR)
+                           << "ICE server parsing failed: Empty uri.");
         }
         RTCError err =
             ParseIceServerUrl(server, url, stun_servers, turn_servers);
@@ -363,8 +359,8 @@
         return err;
       }
     } else {
-      LOG_AND_RETURN_ERROR(RTCErrorType::SYNTAX_ERROR,
-                           "ICE server parsing failed: Empty uri.");
+      return LOG_ERROR(RTCError(RTCErrorType::SYNTAX_ERROR)
+                       << "ICE server parsing failed: Empty uri.");
     }
   }
   return RTCError::OK();
diff --git a/pc/jsep_transport_controller.cc b/pc/jsep_transport_controller.cc
index 2dd7f4f..4d2126e 100644
--- a/pc/jsep_transport_controller.cc
+++ b/pc/jsep_transport_controller.cc
@@ -421,8 +421,8 @@
 RTCError JsepTransportController::RollbackTransports_n() {
   bundles_.Rollback();
   if (!transports_.RollbackTransports()) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
-                         "Failed to roll back transport state.");
+    return LOG_ERROR(RTCError(RTCErrorType::INTERNAL_ERROR)
+                     << "Failed to roll back transport state.");
   }
   return RTCError::OK();
 }
@@ -701,10 +701,9 @@
 
     JsepTransport* transport = GetJsepTransportForMid(content_info.mid());
     if (!transport) {
-      LOG_AND_RETURN_ERROR(
-          RTCErrorType::INVALID_PARAMETER,
-          "Could not find transport for m= section with mid='" +
-              content_info.mid() + "'");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                       << "Could not find transport for m= section with mid='"
+                       << content_info.mid() << "'");
     }
 
     if (established_bundle_group &&
@@ -744,10 +743,10 @@
     }
 
     if (!error.ok()) {
-      LOG_AND_RETURN_ERROR(
-          RTCErrorType::INVALID_PARAMETER,
-          "Failed to apply the description for m= section with mid='" +
-              content_info.mid() + "': " + error.message());
+      return LOG_ERROR(
+          RTCError(RTCErrorType::INVALID_PARAMETER)
+          << "Failed to apply the description for m= section with mid='"
+          << content_info.mid() << "': " << error.message());
     }
   }
   if (type == SdpType::kAnswer) {
diff --git a/pc/media_session.cc b/pc/media_session.cc
index 0ff4bef..79bc2f4 100644
--- a/pc/media_session.cc
+++ b/pc/media_session.cc
@@ -400,8 +400,8 @@
   if (!AddStreamParams(media_description_options.sender_options,
                        session_options.rtcp_cname, ssrc_generator,
                        current_streams, offer, field_trials)) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
-                         "Failed to add stream parameters");
+    return LOG_ERROR(RTCError(RTCErrorType::INTERNAL_ERROR)
+                     << "Failed to add stream parameters");
   }
 
   return CreateContentOffer(media_description_options, session_options,
@@ -797,9 +797,9 @@
     if (!offer_bundle.content_names().empty()) {
       offer->AddGroup(offer_bundle);
       if (!UpdateTransportInfoForBundle(offer_bundle, offer.get())) {
-        LOG_AND_RETURN_ERROR(
-            RTCErrorType::INTERNAL_ERROR,
-            "CreateOffer failed to UpdateTransportInfoForBundle");
+        return LOG_ERROR(
+            RTCError(RTCErrorType::INTERNAL_ERROR)
+            << "CreateOffer failed to UpdateTransportInfoForBundle");
       }
     }
   }
@@ -830,7 +830,8 @@
     const MediaSessionOptions& session_options,
     const SessionDescription* current_description) const {
   if (!offer) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, "Called without offer.");
+    return LOG_ERROR(RTCError(RTCErrorType::INTERNAL_ERROR)
+                     << "Called without offer.");
   }
 
   // Must have options for exactly as many sections as in the offer.
@@ -989,9 +990,9 @@
         // Share the same ICE credentials and crypto params across all contents,
         // as BUNDLE requires.
         if (!UpdateTransportInfoForBundle(answer_bundle, answer.get())) {
-          LOG_AND_RETURN_ERROR(
-              RTCErrorType::INTERNAL_ERROR,
-              "CreateAnswer failed to UpdateTransportInfoForBundle.");
+          return LOG_ERROR(
+              RTCError(RTCErrorType::INTERNAL_ERROR)
+              << "CreateAnswer failed to UpdateTransportInfoForBundle.");
         }
       }
     }
@@ -1332,9 +1333,9 @@
       media_description_options.transport_options, current_description,
       !offer_content->rejected && bundle_transport == nullptr, ice_credentials);
   if (!transport) {
-    LOG_AND_RETURN_ERROR(
-        RTCErrorType::INTERNAL_ERROR,
-        "Failed to create transport answer, transport is missing");
+    return LOG_ERROR(
+        RTCError(RTCErrorType::INTERNAL_ERROR)
+        << "Failed to create transport answer, transport is missing");
   }
 
   // Pick codecs based on the requested communications direction in the offer
@@ -1387,16 +1388,16 @@
                          ssrc_generator(), current_streams,
                          answer_content.get(),
                          transport_desc_factory_->trials())) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
-                         "Failed to set codecs in answer");
+    return LOG_ERROR(RTCError(RTCErrorType::INTERNAL_ERROR)
+                     << "Failed to set codecs in answer");
   }
   if (!CreateMediaContentAnswer(
           offer_content_description, media_description_options, session_options,
           filtered_rtp_header_extensions(header_extensions), ssrc_generator(),
           enable_encrypted_rtp_header_extensions_, current_streams,
           bundle_enabled, answer_content.get())) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
-                         "Failed to create answer");
+    return LOG_ERROR(RTCError(RTCErrorType::INTERNAL_ERROR)
+                     << "Failed to create answer");
   }
 
   bool secure = bundle_transport ? bundle_transport->description.secure()
@@ -1437,9 +1438,9 @@
       media_description_options.transport_options, current_description,
       !offer_content->rejected && bundle_transport == nullptr, ice_credentials);
   if (!data_transport) {
-    LOG_AND_RETURN_ERROR(
-        RTCErrorType::INTERNAL_ERROR,
-        "Failed to create transport answer, data transport is missing");
+    return LOG_ERROR(
+        RTCError(RTCErrorType::INTERNAL_ERROR)
+        << "Failed to create transport answer, data transport is missing");
   }
 
   bool bundle_enabled = offer_description->HasGroup(GROUP_TYPE_BUNDLE) &&
@@ -1469,8 +1470,8 @@
             RtpHeaderExtensions(), ssrc_generator(),
             enable_encrypted_rtp_header_extensions_, current_streams,
             bundle_enabled, data_answer.get())) {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
-                           "Failed to create answer");
+      return LOG_ERROR(RTCError(RTCErrorType::INTERNAL_ERROR)
+                       << "Failed to create answer");
     }
     // Respond with sctpmap if the offer uses sctpmap.
     bool offer_uses_sctpmap = offer_data_description->use_sctpmap();
@@ -1530,9 +1531,9 @@
           !offer_content->rejected && bundle_transport == nullptr,
           ice_credentials);
   if (!unsupported_transport) {
-    LOG_AND_RETURN_ERROR(
-        RTCErrorType::INTERNAL_ERROR,
-        "Failed to create transport answer, unsupported transport is missing");
+    return LOG_ERROR(RTCError(RTCErrorType::INTERNAL_ERROR)
+                     << "Failed to create transport answer, unsupported "
+                        "transport is missing");
   }
   RTC_CHECK(IsMediaContentOfType(offer_content, MediaType::UNSUPPORTED));
 
diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc
index 6270413..75b0b0e 100644
--- a/pc/peer_connection.cc
+++ b/pc/peer_connection.cc
@@ -276,9 +276,9 @@
   // in new candidates being gathered.
   if (previous_ice_candidate_pool_size.has_value() &&
       ice_candidate_pool_size != previous_ice_candidate_pool_size.value()) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_MODIFICATION,
-                         "Can't change candidate pool size after calling "
-                         "SetLocalDescription.");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_MODIFICATION)
+                     << "Can't change candidate pool size after calling "
+                        "SetLocalDescription.");
   }
 
   return RTCError::OK();
@@ -331,8 +331,8 @@
       configuration.stable_writable_connection_ping_interval_ms;
 
   if (configuration != modified_config) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_MODIFICATION,
-                         "Modifying the configuration in an unsupported way.");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_MODIFICATION)
+                     << "Modifying the configuration in an unsupported way.");
   }
 
   RTCError err = IceConfig(modified_config).IsValid();
@@ -956,25 +956,26 @@
   RTC_DCHECK_RUN_ON(signaling_thread());
   TRACE_EVENT0("webrtc", "PeerConnection::AddTrack");
   if (!ConfiguredForMedia()) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION,
-                         "Not configured for media");
+    return LOG_ERROR(RTCError(RTCErrorType::UNSUPPORTED_OPERATION)
+                     << "Not configured for media");
   }
   if (!track) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, "Track is null.");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                     << "Track is null.");
   }
   if (!(track->kind() == MediaStreamTrackInterface::kAudioKind ||
         track->kind() == MediaStreamTrackInterface::kVideoKind)) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                         "Track has invalid kind: " + track->kind());
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                     << "Track has invalid kind: " << track->kind());
   }
   if (IsClosed()) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_STATE,
-                         "PeerConnection is closed.");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_STATE)
+                     << "PeerConnection is closed.");
   }
   if (rtp_manager()->FindSenderForTrack(track.get())) {
-    LOG_AND_RETURN_ERROR(
-        RTCErrorType::INVALID_PARAMETER,
-        "Sender already exists for track " + track->id() + ".");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                     << "Sender already exists for track " << track->id()
+                     << ".");
   }
   RTCErrorOr<scoped_refptr<RtpSenderInterface>> sender_or_error;
   if (IsUnifiedPlan()) {
@@ -1000,15 +1001,16 @@
     scoped_refptr<RtpSenderInterface> sender) {
   RTC_DCHECK_RUN_ON(signaling_thread());
   if (!ConfiguredForMedia()) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION,
-                         "Not configured for media");
+    return LOG_ERROR(RTCError(RTCErrorType::UNSUPPORTED_OPERATION)
+                     << "Not configured for media");
   }
   if (!sender) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, "Sender is null.");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                     << "Sender is null.");
   }
   if (IsClosed()) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_STATE,
-                         "PeerConnection is closed.");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_STATE)
+                     << "PeerConnection is closed.");
   }
   if (IsUnifiedPlan()) {
     auto transceiver = FindTransceiverBySender(sender);
@@ -1038,9 +1040,9 @@
     }
     RTC_ALLOW_PLAN_B_DEPRECATION_END();
     if (!removed) {
-      LOG_AND_RETURN_ERROR(
-          RTCErrorType::INVALID_PARAMETER,
-          "Couldn't find sender " + sender->id() + " to remove.");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                       << "Couldn't find sender " << sender->id()
+                       << " to remove.");
     }
   }
   sdp_handler_->UpdateNegotiationNeeded();
@@ -1056,8 +1058,8 @@
 RTCErrorOr<scoped_refptr<RtpTransceiverInterface>>
 PeerConnection::AddTransceiver(scoped_refptr<MediaStreamTrackInterface> track) {
   if (!ConfiguredForMedia()) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION,
-                         "Not configured for media");
+    return LOG_ERROR(RTCError(RTCErrorType::UNSUPPORTED_OPERATION)
+                     << "Not configured for media");
   }
 
   return AddTransceiver(track, RtpTransceiverInit());
@@ -1068,13 +1070,14 @@
                                const RtpTransceiverInit& init) {
   RTC_DCHECK_RUN_ON(signaling_thread());
   if (!ConfiguredForMedia()) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION,
-                         "Not configured for media");
+    return LOG_ERROR(RTCError(RTCErrorType::UNSUPPORTED_OPERATION)
+                     << "Not configured for media");
   }
   RTC_CHECK(IsUnifiedPlan())
       << "AddTransceiver is only available with Unified Plan SdpSemantics";
   if (!track) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, "track is null");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                     << "track is null");
   }
   MediaType media_type;
   if (track->kind() == MediaStreamTrackInterface::kAudioKind) {
@@ -1082,8 +1085,8 @@
   } else if (track->kind() == MediaStreamTrackInterface::kVideoKind) {
     media_type = MediaType::VIDEO;
   } else {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                         "Track kind is not audio or video");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                     << "Track kind is not audio or video");
   }
   return AddTransceiver(media_type, track, init);
 }
@@ -1098,14 +1101,14 @@
                                const RtpTransceiverInit& init) {
   RTC_DCHECK_RUN_ON(signaling_thread());
   if (!ConfiguredForMedia()) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION,
-                         "Not configured for media");
+    return LOG_ERROR(RTCError(RTCErrorType::UNSUPPORTED_OPERATION)
+                     << "Not configured for media");
   }
   RTC_CHECK(IsUnifiedPlan())
       << "AddTransceiver is only available with Unified Plan SdpSemantics";
   if (!(media_type == MediaType::AUDIO || media_type == MediaType::VIDEO)) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                         "media type is not audio or video");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                     << "media type is not audio or video");
   }
   return AddTransceiver(media_type, nullptr, init);
 }
@@ -1117,8 +1120,8 @@
                                bool update_negotiation_needed) {
   RTC_DCHECK_RUN_ON(signaling_thread());
   if (!ConfiguredForMedia()) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION,
-                         "Not configured for media");
+    return LOG_ERROR(RTCError(RTCErrorType::UNSUPPORTED_OPERATION)
+                     << "Not configured for media");
   }
   RTC_DCHECK(
       (media_type == MediaType::AUDIO || media_type == MediaType::VIDEO));
@@ -1134,26 +1137,26 @@
                                        return !encoding.rid.empty();
                                      });
   if (num_rids > 0 && num_rids != init.send_encodings.size()) {
-    LOG_AND_RETURN_ERROR(
-        RTCErrorType::INVALID_PARAMETER,
-        "RIDs must be provided for either all or none of the send encodings.");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                     << "RIDs must be provided for either all or none of the "
+                        "send encodings.");
   }
 
   if (num_rids > 0 && absl::c_any_of(init.send_encodings,
                                      [](const RtpEncodingParameters& encoding) {
                                        return !IsLegalRsidName(encoding.rid);
                                      })) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                         "Invalid RID value provided.");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                     << "Invalid RID value provided.");
   }
 
   if (absl::c_any_of(init.send_encodings,
                      [](const RtpEncodingParameters& encoding) {
                        return encoding.ssrc.has_value();
                      })) {
-    LOG_AND_RETURN_ERROR(
-        RTCErrorType::UNSUPPORTED_PARAMETER,
-        "Attempted to set an unimplemented parameter of RtpParameters.");
+    return LOG_ERROR(
+        RTCError(RTCErrorType::UNSUPPORTED_PARAMETER)
+        << "Attempted to set an unimplemented parameter of RtpParameters.");
   }
 
   RtpParameters parameters;
@@ -1189,9 +1192,9 @@
   }
 
   if (UnimplementedRtpParameterHasValue(parameters)) {
-    LOG_AND_RETURN_ERROR(
-        RTCErrorType::UNSUPPORTED_PARAMETER,
-        "Attempted to set an unimplemented parameter of RtpParameters.");
+    return LOG_ERROR(
+        RTCError(RTCErrorType::UNSUPPORTED_PARAMETER)
+        << "Attempted to set an unimplemented parameter of RtpParameters.");
   }
 
   std::vector<Codec> codecs;
@@ -1210,7 +1213,7 @@
     if (result.type() == RTCErrorType::INVALID_MODIFICATION) {
       result.set_type(RTCErrorType::UNSUPPORTED_OPERATION);
     }
-    LOG_AND_RETURN_ERROR(result.type(), result.message());
+    return LOG_ERROR(RTCError(result.type()) << result.message());
   }
 
   RTC_LOG(LS_INFO) << "Adding " << MediaTypeToString(media_type)
@@ -1486,8 +1489,8 @@
   TRACE_EVENT0("webrtc", "PeerConnection::CreateDataChannel");
 
   if (IsClosed()) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_STATE,
-                         "CreateDataChannelOrError: PeerConnection is closed.");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_STATE)
+                     << "CreateDataChannelOrError: PeerConnection is closed.");
   }
 
   bool first_datachannel = !data_channel_controller_.HasUsedDataChannels();
@@ -1615,8 +1618,8 @@
   RTC_DCHECK_RUN_ON(signaling_thread());
   TRACE_EVENT0("webrtc", "PeerConnection::SetConfiguration");
   if (IsClosed()) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_STATE,
-                         "SetConfiguration: PeerConnection is closed.");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_STATE)
+                     << "SetConfiguration: PeerConnection is closed.");
   }
 
   const bool has_local_description = local_description() != nullptr;
@@ -1632,9 +1635,9 @@
 
   if (has_local_description &&
       configuration.crypto_options != configuration_.crypto_options) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_MODIFICATION,
-                         "Can't change crypto_options after calling "
-                         "SetLocalDescription.");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_MODIFICATION)
+                     << "Can't change crypto_options after calling "
+                        "SetLocalDescription.");
   }
 
   // Create a new, configuration object whose peerconnection config
@@ -1688,8 +1691,8 @@
                 modified_config.stun_candidate_keepalive_interval,
                 has_local_description);
           })) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
-                         "Failed to apply configuration to PortAllocator.");
+    return LOG_ERROR(RTCError(RTCErrorType::INTERNAL_ERROR)
+                     << "Failed to apply configuration to PortAllocator.");
   }
 
   configuration_ = modified_config;
@@ -1725,36 +1728,36 @@
   RTC_DCHECK_RUN_ON(worker_thread());
 
   if (!call_) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_STATE,
-                         "PeerConnection is closed.");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_STATE)
+                     << "PeerConnection is closed.");
   }
 
   const bool has_min = bitrate.min_bitrate_bps.has_value();
   const bool has_start = bitrate.start_bitrate_bps.has_value();
   const bool has_max = bitrate.max_bitrate_bps.has_value();
   if (has_min && *bitrate.min_bitrate_bps < 0) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                         "min_bitrate_bps <= 0");
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                     << "min_bitrate_bps <= 0");
   }
   if (has_start) {
     if (has_min && *bitrate.start_bitrate_bps < *bitrate.min_bitrate_bps) {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                           "start_bitrate_bps < min_bitrate_bps");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                       << "start_bitrate_bps < min_bitrate_bps");
     } else if (*bitrate.start_bitrate_bps < 0) {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                           "curent_bitrate_bps < 0");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                       << "curent_bitrate_bps < 0");
     }
   }
   if (has_max) {
     if (has_start && *bitrate.max_bitrate_bps < *bitrate.start_bitrate_bps) {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                           "max_bitrate_bps < start_bitrate_bps");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                       << "max_bitrate_bps < start_bitrate_bps");
     } else if (has_min && *bitrate.max_bitrate_bps < *bitrate.min_bitrate_bps) {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                           "max_bitrate_bps < min_bitrate_bps");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                       << "max_bitrate_bps < min_bitrate_bps");
     } else if (*bitrate.max_bitrate_bps < 0) {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                           "max_bitrate_bps < 0");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                       << "max_bitrate_bps < 0");
     }
   }
 
@@ -3121,8 +3124,8 @@
         transport_controller_n()->GetSctpTransport(mid);
     RTC_DCHECK(sctp_transport);
     if (!sctp_transport || !sctp_transport->Start(options)) {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_MODIFICATION,
-                           "Failed to start SCTP transport.");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_MODIFICATION)
+                       << "Failed to start SCTP transport.");
     }
     return RTCError::OK();
   });
diff --git a/pc/sdp_offer_answer.cc b/pc/sdp_offer_answer.cc
index a182232..e4e996f 100644
--- a/pc/sdp_offer_answer.cc
+++ b/pc/sdp_offer_answer.cc
@@ -370,13 +370,13 @@
 
     if (!RtpTransceiverDirectionHasRecv(local_direction) &&
         RtpTransceiverDirectionHasSend(remote_direction)) {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                           "Incompatible receive direction");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                       << "Incompatible receive direction");
     }
     if (!RtpTransceiverDirectionHasSend(local_direction) &&
         RtpTransceiverDirectionHasRecv(remote_direction)) {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                           "Incompatible send direction");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                       << "Incompatible send direction");
     }
   }
   return RTCError::OK();
@@ -413,15 +413,17 @@
     const TransportInfo* tinfo = desc->GetTransportInfoByName(mid);
     if (!media || !tinfo) {
       // Something is not right.
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, kInvalidSdp);
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                       << kInvalidSdp);
     }
     if (dtls_enabled) {
       if (!tinfo->description.identity_fingerprint) {
-        LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                             kSdpWithoutDtlsFingerprint);
+        return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                         << kSdpWithoutDtlsFingerprint);
       }
     } else {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, kSdpWithoutCrypto);
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                       << kSdpWithoutCrypto);
     }
   }
   return RTCError::OK();
@@ -469,17 +471,17 @@
   flat_set<absl::string_view> mids;
   for (const ContentInfo& content : description.contents()) {
     if (content.mid().empty()) {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                           "A media section is missing a MID attribute.");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                       << "A media section is missing a MID attribute.");
     }
     if (content.mid().size() > kMidMaxSize) {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                           "The MID attribute exceeds the maximum supported "
-                           "length of 16 characters.");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                       << "The MID attribute exceeds the maximum supported "
+                          "length of 16 characters.");
     }
     if (!mids.insert(content.mid()).second) {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                           "Duplicate a=mid value '" + content.mid() + "'.");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                       << "Duplicate a=mid value '" << content.mid() << "'.");
     }
   }
   return RTCError::OK();
@@ -499,7 +501,7 @@
        << ". All codecs must share the same type, "
           "encoding name, clock rate and parameters.";
 
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, sb.Release());
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER) << sb.Release());
   }
   payload_to_codec_parameters.insert(
       std::make_pair(codec_parameters.payload_type, codec_parameters));
@@ -520,9 +522,9 @@
       const ContentInfo* content_description =
           description.GetContentByName(content_name);
       if (!content_description) {
-        LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                             "A BUNDLE group contains a MID='" + content_name +
-                                 "' matching no m= section.");
+        return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                         << "A BUNDLE group contains a MID='" << content_name
+                         << "' matching no m= section.");
       }
       const MediaContentDescription* media_description =
           content_description->media_description();
@@ -553,12 +555,12 @@
   if (existing_extension != id_to_extension.end() &&
       !(extension.uri == existing_extension->second.uri &&
         extension.encrypt == existing_extension->second.encrypt)) {
-    LOG_AND_RETURN_ERROR(
-        RTCErrorType::INVALID_PARAMETER,
-        "A BUNDLE group contains a codec collision for "
-        "header extension id=" +
-            absl::StrCat(extension.id) +
-            ". The id must be the same across all bundled media descriptions");
+    return LOG_ERROR(
+        RTCError(RTCErrorType::INVALID_PARAMETER)
+        << "A BUNDLE group contains a codec collision for "
+           "header extension id="
+        << extension.id
+        << ". The id must be the same across all bundled media descriptions");
   }
   id_to_extension.insert(std::make_pair(extension.id, extension));
   return RTCError::OK();
@@ -577,9 +579,9 @@
       const ContentInfo* content_description =
           description.GetContentByName(content_name);
       if (!content_description) {
-        LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                             "A BUNDLE group contains a MID='" + content_name +
-                                 "' matching no m= section.");
+        return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                         << "A BUNDLE group contains a MID='" << content_name
+                         << "' matching no m= section.");
       }
       const MediaContentDescription* media_description =
           content_description->media_description();
@@ -616,10 +618,10 @@
       return ext.uri == RtpExtension::kRidUri;
     });
     if (it == extensions.end()) {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                           "The media section with MID='" + content.mid() +
-                               "' negotiates simulcast but does not negotiate "
-                               "the RID RTP header extension.");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                       << "The media section with MID='" << content.mid()
+                       << "' negotiates simulcast but does not negotiate "
+                          "the RID RTP header extension.");
     }
   }
   return RTCError::OK();
@@ -640,11 +642,11 @@
              group.ssrcs.size() != 2) ||
             (group.semantics == kSimSsrcGroupSemantics &&
              group.ssrcs.size() > kMaxSimulcastStreams)) {
-          LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                               "The media section with MID='" + content.mid() +
-                                   "' has a ssrc-group with semantics " +
-                                   group.semantics +
-                                   " and an unexpected number of SSRCs.");
+          return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                           << "The media section with MID='" << content.mid()
+                           << "' has a ssrc-group with semantics "
+                           << group.semantics
+                           << " and an unexpected number of SSRCs.");
         }
       }
     }
@@ -667,12 +669,12 @@
     if (type == MediaType::AUDIO || type == MediaType::VIDEO) {
       for (const auto& codec : media_description->codecs()) {
         if (!PayloadType::IsValid(codec.id, media_description->rtcp_mux())) {
-          LOG_AND_RETURN_ERROR(
-              RTCErrorType::INVALID_PARAMETER,
-              "The media section with MID='" + content.mid() +
-                  "' used an invalid payload type " + absl::StrCat(codec.id) +
-                  " for codec '" + codec.name + ", rtcp-mux:" +
-                  (media_description->rtcp_mux() ? "enabled" : "disabled"));
+          return LOG_ERROR(
+              RTCError(RTCErrorType::INVALID_PARAMETER)
+              << "The media section with MID='" << content.mid()
+              << "' used an invalid payload type " << codec.id << " for codec '"
+              << codec.name << ", rtcp-mux:"
+              << (media_description->rtcp_mux() ? "enabled" : "disabled"));
         }
       }
     }
@@ -2009,7 +2011,8 @@
 
   pending_ice_restarts_.clear();
   if (session_error() != SessionError::kNone) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, GetSessionErrorMsg());
+    return LOG_ERROR(RTCError(RTCErrorType::INTERNAL_ERROR)
+                     << GetSessionErrorMsg());
   }
 
   // Validate SSRCs, we do not allow duplicates.
@@ -2020,9 +2023,8 @@
         for (uint32_t ssrc : stream.ssrcs) {
           auto result = used_ssrcs.insert(ssrc);
           if (!result.second) {
-            LOG_AND_RETURN_ERROR(
-                RTCErrorType::INVALID_PARAMETER,
-                "Duplicate ssrc " + absl::StrCat(ssrc) + " is not allowed");
+            return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                             << "Duplicate ssrc " << ssrc << " is not allowed");
           }
         }
       }
@@ -3409,11 +3411,9 @@
   auto state = signaling_state();
   if (state != PeerConnectionInterface::kHaveLocalOffer &&
       state != PeerConnectionInterface::kHaveRemoteOffer) {
-    LOG_AND_RETURN_ERROR(
-        RTCErrorType::INVALID_STATE,
-        (StringBuilder("Called in wrong signalingState: ")
-         << (PeerConnectionInterface::AsString(signaling_state())))
-            .Release());
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_STATE)
+                     << "Called in wrong signalingState: "
+                     << PeerConnectionInterface::AsString(signaling_state()));
   }
   RTC_DCHECK_RUN_ON(signaling_thread());
   RTC_DCHECK(IsUnifiedPlan());
@@ -3865,17 +3865,15 @@
   RTC_DCHECK_EQ(SessionError::kNone, session_error());
 
   if (!sdesc || !sdesc->description()) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, kInvalidSdp);
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER) << kInvalidSdp);
   }
 
   SdpType type = sdesc->GetType();
   if ((source == CS_LOCAL && !ExpectSetLocalDescription(type)) ||
       (source == CS_REMOTE && !ExpectSetRemoteDescription(type))) {
-    LOG_AND_RETURN_ERROR(
-        RTCErrorType::INVALID_STATE,
-        (StringBuilder("Called in wrong state: ")
-         << PeerConnectionInterface::AsString(signaling_state()))
-            .Release());
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_STATE)
+                     << "Called in wrong state: "
+                     << PeerConnectionInterface::AsString(signaling_state()));
   }
 
   RTCError error = ValidateMids(*sdesc->description());
@@ -3894,8 +3892,8 @@
 
   // Verify ice-ufrag and ice-pwd.
   if (!VerifyIceUfragPwdPresent(sdesc->description(), bundle_groups_by_mid)) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                         kSdpWithoutIceUfragPwd);
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                     << kSdpWithoutIceUfragPwd);
   }
 
   // Validate that there are no collisions of bundled payload types.
@@ -3918,8 +3916,8 @@
 
   if (!pc_->ValidateBundleSettings(sdesc->description(),
                                    bundle_groups_by_mid)) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                         kBundleWithoutRtcpMux);
+    return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                     << kBundleWithoutRtcpMux);
   }
 
   error = ValidatePayloadTypes(*sdesc->description());
@@ -3940,8 +3938,8 @@
     if (!MediaSectionsHaveSameCount(*offer_desc, *sdesc->description()) ||
         !MediaSectionsInSameOrder(*offer_desc, nullptr, *sdesc->description(),
                                   type)) {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                           kMlineMismatchInAnswer);
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                       << kMlineMismatchInAnswer);
     }
   } else {
     // The re-offers should respect the order of m= sections in current
@@ -3965,8 +3963,8 @@
     if (current_desc &&
         !MediaSectionsInSameOrder(*current_desc, secondary_current_desc,
                                   *sdesc->description(), type)) {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                           kMlineMismatchInSubsequentOffer);
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                       << kMlineMismatchInSubsequentOffer);
     }
   }
 
@@ -3981,10 +3979,10 @@
       if ((desc.type() == MediaType::AUDIO ||
            desc.type() == MediaType::VIDEO) &&
           desc.streams().size() > 1u) {
-        LOG_AND_RETURN_ERROR(
-            RTCErrorType::INVALID_PARAMETER,
-            "Media section has more than one track specified with a=ssrc lines "
-            "which is not supported with Unified Plan.");
+        return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                         << "Media section has more than one track specified "
+                            "with a=ssrc lines which is not supported with "
+                            "Unified Plan.");
       }
     }
     // Validate spec-simulcast which only works if the remote end negotiated the
@@ -4028,9 +4026,9 @@
     if (pc_->configuration()->bundle_policy ==
             PeerConnectionInterface::kBundlePolicyMaxBundle &&
         bundle_groups_by_mid.empty()) {
-      LOG_AND_RETURN_ERROR(
-          RTCErrorType::INVALID_PARAMETER,
-          "max-bundle configured but session description has no BUNDLE group");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                       << "max-bundle configured but session description has "
+                          "no BUNDLE group");
     }
   }
 
@@ -4121,8 +4119,8 @@
     } else if (media_type == MediaType::UNSUPPORTED) {
       RTC_LOG(LS_INFO) << "Ignoring unsupported media type";
     } else {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
-                           "Unknown section type.");
+      return LOG_ERROR(RTCError(RTCErrorType::INTERNAL_ERROR)
+                       << "Unknown section type.");
     }
   }
 
@@ -4166,8 +4164,8 @@
     }
     if (!transceiver) {
       // This may happen normally when media sections are rejected.
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                           "Transceiver not found based on m-line index");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                       << "Transceiver not found based on m-line index");
     }
   } else {
     RTC_DCHECK_EQ(source, CS_REMOTE);
@@ -4225,9 +4223,9 @@
   }
 
   if (transceiver->media_type() != media_desc->type()) {
-    LOG_AND_RETURN_ERROR(
-        RTCErrorType::INVALID_PARAMETER,
-        "Transceiver type does not match media description type.");
+    return LOG_ERROR(
+        RTCError(RTCErrorType::INVALID_PARAMETER)
+        << "Transceiver type does not match media description type.");
   }
 
   if (media_desc->HasSimulcast()) {
@@ -4306,8 +4304,8 @@
     error.set_error_detail(RTCErrorDetailType::DATA_CHANNEL_FAILURE);
     pc_->DestroyDataChannelTransport(error);
   } else if (!pc_->CreateDataChannelTransport(content.mid())) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
-                         "Failed to create data channel.");
+    return LOG_ERROR(RTCError(RTCErrorType::INTERNAL_ERROR)
+                     << "Failed to create data channel.");
   }
   return RTCError::OK();
 }
@@ -4895,8 +4893,8 @@
   } else if (options.offer_to_receive_audio == 1) {
     AddUpToOneReceivingTransceiverOfType(MediaType::AUDIO);
   } else if (options.offer_to_receive_audio > 1) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_PARAMETER,
-                         "offer_to_receive_audio > 1 is not supported.");
+    return LOG_ERROR(RTCError(RTCErrorType::UNSUPPORTED_PARAMETER)
+                     << "offer_to_receive_audio > 1 is not supported.");
   }
 
   if (options.offer_to_receive_video == 0) {
@@ -4904,8 +4902,8 @@
   } else if (options.offer_to_receive_video == 1) {
     AddUpToOneReceivingTransceiverOfType(MediaType::VIDEO);
   } else if (options.offer_to_receive_video > 1) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_PARAMETER,
-                         "offer_to_receive_video > 1 is not supported.");
+    return LOG_ERROR(RTCError(RTCErrorType::UNSUPPORTED_PARAMETER)
+                     << "offer_to_receive_video > 1 is not supported.");
   }
 
   return RTCError::OK();
@@ -5173,8 +5171,8 @@
       // Note that this is never expected to fail, since RtpDemuxer doesn't
       // return an error when changing payload type demux criteria, which is all
       // this does.
-      LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
-                           "Failed to update payload type demuxing state.");
+      return LOG_ERROR(RTCError(RTCErrorType::INTERNAL_ERROR)
+                       << "Failed to update payload type demuxing state.");
     }
 
     // Push down the new SDP media section for each audio/video transceiver.
@@ -5592,10 +5590,10 @@
           return content_info.mid() == candidate->sdp_mid();
         });
     if (it == contents.end()) {
-      LOG_AND_RETURN_ERROR(
-          RTCErrorType::INVALID_PARAMETER,
-          "Mid " + candidate->sdp_mid() +
-              " specified but no media section with that mid found.");
+      return LOG_ERROR(
+          RTCError(RTCErrorType::INVALID_PARAMETER)
+          << "Mid " << candidate->sdp_mid()
+          << " specified but no media section with that mid found.");
     } else {
       return &*it;
     }
@@ -5606,16 +5604,15 @@
     if (mediacontent_index < content_size) {
       return &description->description()->contents()[mediacontent_index];
     } else {
-      LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE,
-                           "Media line index (" +
-                               absl::StrCat(candidate->sdp_mline_index()) +
-                               ") out of range (number of mlines: " +
-                               absl::StrCat(content_size) + ").");
+      return LOG_ERROR(RTCError(RTCErrorType::INVALID_RANGE)
+                       << "Media line index (" << candidate->sdp_mline_index()
+                       << ") out of range (number of mlines: " << content_size
+                       << ").");
     }
   }
 
-  LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
-                       "Neither sdp_mline_index nor sdp_mid specified.");
+  return LOG_ERROR(RTCError(RTCErrorType::INVALID_PARAMETER)
+                   << "Neither sdp_mline_index nor sdp_mid specified.");
 }
 
 RTCError SdpOfferAnswerHandler::CreateChannels(const SessionDescription& desc) {
@@ -5663,8 +5660,8 @@
   const ContentInfo* data = GetFirstDataContent(&desc);
   if (data && !data->rejected &&
       !pc_->CreateDataChannelTransport(data->mid())) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
-                         "Failed to create data channel.");
+    return LOG_ERROR(RTCError(RTCErrorType::INTERNAL_ERROR)
+                     << "Failed to create data channel.");
   }
 
   return RTCError::OK();