Browse Source

Merge pull request #962 from paullouisageneau/ice-set-remote-invalid-argument

More consistent exceptions for remote description checks
Paul-Louis Ageneau 1 year ago
parent
commit
327ee9fbad
2 changed files with 11 additions and 11 deletions
  1. 5 5
      src/description.cpp
  2. 6 6
      src/impl/icetransport.cpp

+ 5 - 5
src/description.cpp

@@ -691,7 +691,7 @@ Description::Entry::ExtMap::ExtMap(string_view description) { setDescription(des
 void Description::Entry::ExtMap::setDescription(string_view description) {
 	const size_t uriStart = description.find(' ');
 	if (uriStart == string::npos)
-		throw std::invalid_argument("Invalid description");
+		throw std::invalid_argument("Invalid description for extmap");
 
 	const string_view idAndDirection = description.substr(0, uriStart);
 	const size_t idSplit = idAndDirection.find('/');
@@ -710,7 +710,7 @@ void Description::Entry::ExtMap::setDescription(string_view description) {
 		else if (directionStr == "inactive")
 			this->direction = Direction::Inactive;
 		else
-			throw std::invalid_argument("Invalid direction");
+			throw std::invalid_argument("Invalid direction for extmap");
 	}
 
 	const string_view uriAndAttributes = description.substr(uriStart + 1);
@@ -855,7 +855,7 @@ Description::Media::Media(const string &sdp) : Entry(sdp, "", Direction::Unknown
 	}
 
 	if (mid().empty())
-		throw std::invalid_argument("Missing mid in media SDP");
+		throw std::invalid_argument("Missing mid in media description");
 }
 
 Description::Media::Media(const string &mline, string mid, Direction dir)
@@ -1074,14 +1074,14 @@ Description::Media::RtpMap::RtpMap(string_view description) { setDescription(des
 void Description::Media::RtpMap::setDescription(string_view description) {
 	size_t p = description.find(' ');
 	if (p == string::npos)
-		throw std::invalid_argument("Invalid format description");
+		throw std::invalid_argument("Invalid format description for rtpmap");
 
 	this->payloadType = to_integer<int>(description.substr(0, p));
 
 	string_view line = description.substr(p + 1);
 	size_t spl = line.find('/');
 	if (spl == string::npos)
-		throw std::invalid_argument("Invalid format description");
+		throw std::invalid_argument("Invalid format description for rtpmap");
 
 	this->format = line.substr(0, spl);
 

+ 6 - 6
src/impl/icetransport.cpp

@@ -182,7 +182,7 @@ void IceTransport::setRemoteDescription(const Description &description) {
 	// See https://www.rfc-editor.org/rfc/rfc5763.html#section-5
 	if (description.type() == Description::Type::Answer &&
 	    description.role() == Description::Role::ActPass)
-		throw std::logic_error("Illegal role actpass in remote answer description");
+		throw std::invalid_argument("Illegal role actpass in remote answer description");
 
 	// RFC 5763: Note that if the answerer uses setup:passive, then the DTLS handshake
 	// will not begin until the answerer is received, which adds additional latency.
@@ -193,12 +193,12 @@ void IceTransport::setRemoteDescription(const Description &description) {
 		                                                        : Description::Role::Active;
 
 	if (mRole == description.role())
-		throw std::logic_error("Incompatible roles with remote description");
+		throw std::invalid_argument("Incompatible roles with remote description");
 
 	mMid = description.bundleMid();
 	if (juice_set_remote_description(mAgent.get(),
 	                                 description.generateApplicationSdp("\r\n").c_str()) < 0)
-		throw std::runtime_error("Failed to parse ICE settings from remote SDP");
+		throw std::invalid_argument("Invalid ICE settings from remote SDP");
 }
 
 bool IceTransport::addRemoteCandidate(const Candidate &candidate) {
@@ -641,7 +641,7 @@ void IceTransport::setRemoteDescription(const Description &description) {
 	// See https://www.rfc-editor.org/rfc/rfc5763.html#section-5
 	if (description.type() == Description::Type::Answer &&
 	    description.role() == Description::Role::ActPass)
-		throw std::logic_error("Illegal role actpass in remote answer description");
+		throw std::invalid_argument("Illegal role actpass in remote answer description");
 
 	// RFC 5763: Note that if the answerer uses setup:passive, then the DTLS handshake
 	// will not begin until the answerer is received, which adds additional latency.
@@ -652,7 +652,7 @@ void IceTransport::setRemoteDescription(const Description &description) {
 		                                                        : Description::Role::Active;
 
 	if (mRole == description.role())
-		throw std::logic_error("Incompatible roles with remote description");
+		throw std::invalid_argument("Incompatible roles with remote description");
 
 	mMid = description.bundleMid();
 	mTrickleTimeout = !description.ended() ? 30s : 0s;
@@ -660,7 +660,7 @@ void IceTransport::setRemoteDescription(const Description &description) {
 	// Warning: libnice expects "\n" as end of line
 	if (nice_agent_parse_remote_sdp(mNiceAgent.get(),
 	                                description.generateApplicationSdp("\n").c_str()) < 0)
-		throw std::runtime_error("Failed to parse ICE settings from remote SDP");
+		throw std::invalid_argument("Invalid ICE settings from remote SDP");
 }
 
 bool IceTransport::addRemoteCandidate(const Candidate &candidate) {