Adding error enum to be used by PeerConnectionInterface methods.
The enum is at about the same level of detail as DOMExceptions, and I
looked through the spec making sure that chromium will be able to perform
the DOMException mapping for each one.
The new enum is called RtcError and is outside the PeerConnectionInterface
scope, because we may want to use this for things not associated with a
PeerConnection in the future.
This CL doesn't yet use the error enum anywhere; that will probably happen
in follow-up CLs for the individual methods.
BUG=webrtc:6855
Review-Url: https://codereview.webrtc.org/2564683002
Cr-Commit-Position: refs/heads/master@{#15526}
diff --git a/webrtc/api/peerconnection.cc b/webrtc/api/peerconnection.cc
index a47b2f2..e1f19ad 100644
--- a/webrtc/api/peerconnection.cc
+++ b/webrtc/api/peerconnection.cc
@@ -432,6 +432,25 @@
namespace webrtc {
+static const char* const kRtcErrorNames[] = {
+ "NONE",
+ "UNSUPPORTED_PARAMETER",
+ "INVALID_PARAMETER",
+ "INVALID_RANGE",
+ "SYNTAX_ERROR",
+ "INVALID_STATE",
+ "INVALID_MODIFICATION",
+ "NETWORK_ERROR",
+ "INTERNAL_ERROR",
+};
+
+std::ostream& operator<<(std::ostream& stream, RtcError error) {
+ int index = static_cast<int>(error);
+ RTC_CHECK(index < static_cast<int>(sizeof(kRtcErrorNames) /
+ sizeof(kRtcErrorNames[0])));
+ return stream << kRtcErrorNames[index];
+}
+
// Generate a RTCP CNAME when a PeerConnection is created.
std::string GenerateRtcpCname() {
std::string cname;
diff --git a/webrtc/api/peerconnectioninterface.h b/webrtc/api/peerconnectioninterface.h
index 54fae2b..a655756 100644
--- a/webrtc/api/peerconnectioninterface.h
+++ b/webrtc/api/peerconnectioninterface.h
@@ -52,6 +52,7 @@
#define WEBRTC_API_PEERCONNECTIONINTERFACE_H_
#include <memory>
+#include <ostream>
#include <string>
#include <utility>
#include <vector>
@@ -140,6 +141,44 @@
typedef MetricsObserverInterface UMAObserver;
+// Enumeration to represent distinct classes of errors that an application
+// may wish to act upon differently. These roughly map to DOMExceptions in
+// the web API, as described in the comments below.
+enum class RtcError {
+ // No error.
+ NONE,
+ // A supplied parameter is valid, but currently unsupported.
+ // Maps to InvalidAccessError DOMException.
+ UNSUPPORTED_PARAMETER,
+ // General error indicating that a supplied parameter is invalid.
+ // Maps to InvalidAccessError or TypeError DOMException depending on context.
+ INVALID_PARAMETER,
+ // Slightly more specific than INVALID_PARAMETER; a parameter's value was
+ // outside the allowed range.
+ // Maps to RangeError DOMException.
+ INVALID_RANGE,
+ // Slightly more specific than INVALID_PARAMETER; an error occurred while
+ // parsing string input.
+ // Maps to SyntaxError DOMException.
+ SYNTAX_ERROR,
+ // The object does not support this operation in its current state.
+ // Maps to InvalidStateError DOMException.
+ INVALID_STATE,
+ // An attempt was made to modify the object in an invalid way.
+ // Maps to InvalidModificationError DOMException.
+ INVALID_MODIFICATION,
+ // An error occurred within an underlying network protocol.
+ // Maps to NetworkError DOMException.
+ NETWORK_ERROR,
+ // The operation failed due to an internal error.
+ // Maps to OperationError DOMException.
+ INTERNAL_ERROR,
+};
+
+// Outputs the error as a friendly string.
+// Update this method when adding a new error type.
+std::ostream& operator<<(std::ostream& stream, RtcError error);
+
class PeerConnectionInterface : public rtc::RefCountInterface {
public:
// See http://dev.w3.org/2011/webrtc/editor/webrtc.html#state-definitions .
diff --git a/webrtc/api/peerconnectioninterface_unittest.cc b/webrtc/api/peerconnectioninterface_unittest.cc
index d673b41..cfba3e6 100644
--- a/webrtc/api/peerconnectioninterface_unittest.cc
+++ b/webrtc/api/peerconnectioninterface_unittest.cc
@@ -9,6 +9,7 @@
*/
#include <memory>
+#include <sstream>
#include <string>
#include <utility>
@@ -2989,3 +2990,11 @@
EXPECT_TRUE(updated_answer_options.has_audio());
EXPECT_TRUE(updated_answer_options.has_video());
}
+
+TEST(RtcErrorTest, OstreamOperator) {
+ std::ostringstream oss;
+ oss << webrtc::RtcError::NONE << ' '
+ << webrtc::RtcError::INVALID_PARAMETER << ' '
+ << webrtc::RtcError::INTERNAL_ERROR;
+ EXPECT_EQ("NONE INVALID_PARAMETER INTERNAL_ERROR", oss.str());
+}