From 32f3c6cef117e1baea078f562a919adb6ee6a5f4 Mon Sep 17 00:00:00 2001 From: Harald Alvestrand Date: Tue, 21 Jan 2025 12:29:00 +0000 Subject: [PATCH] Add AbslStringify for RtcErrorType and RtcErrorDetail Drive-by: fix MakeVal in rtc_base/checks.h to ensure that StrCat is used for types that have AbslStringify. Bug: None Change-Id: Ia78c65da18b4a826365a6a2c741f11809640197f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374345 Reviewed-by: Evan Shrubsole Commit-Queue: Harald Alvestrand Cr-Commit-Position: refs/heads/main@{#43779} --- api/rtc_error.h | 10 ++++++++++ rtc_base/checks.h | 1 + 2 files changed, 11 insertions(+) diff --git a/api/rtc_error.h b/api/rtc_error.h index 775f6de038..2ed33c41c8 100644 --- a/api/rtc_error.h +++ b/api/rtc_error.h @@ -105,6 +105,16 @@ enum class RTCErrorDetailType { RTC_EXPORT absl::string_view ToString(RTCErrorType error); RTC_EXPORT absl::string_view ToString(RTCErrorDetailType error); +template +void AbslStringify(Sink& sink, RTCErrorType error) { + sink.Append(ToString(error)); +} + +template +void AbslStringify(Sink& sink, RTCErrorDetailType error_detail) { + sink.Append(ToString(error_detail)); +} + // Roughly corresponds to RTCError in the web api. Holds an error type, a // message, and possibly additional information specific to that error. // diff --git a/rtc_base/checks.h b/rtc_base/checks.h index 5842d58858..a562efe74a 100644 --- a/rtc_base/checks.h +++ b/rtc_base/checks.h @@ -212,6 +212,7 @@ inline Val MakeVal( // The enum class types are not implicitly convertible to arithmetic types. template ::value && + !absl::HasAbslStringify::value && !std::is_arithmetic::value>* = nullptr> inline decltype(MakeVal(std::declval>())) MakeVal( T x) {