mirror of
https://github.com/pion/webrtc.git
synced 2025-12-24 11:51:03 +08:00
Add an error for sdp unmarshalling error
Add the publicly available ErrSDPUnmarshal error when an sdp unmarshal fails.
This commit is contained in:
@@ -175,6 +175,9 @@ var (
|
||||
// and the requested SSRC was ignored.
|
||||
ErrSimulcastProbeOverflow = errors.New("simulcast probe limit has been reached, new SSRC has been discarded")
|
||||
|
||||
// ErrSDPUnmarshalling indicates that the SDP could not be unmarshalled.
|
||||
ErrSDPUnmarshalling = errors.New("failed to unmarshal SDP")
|
||||
|
||||
errDetachNotEnabled = errors.New("enable detaching by calling webrtc.DetachDataChannels()")
|
||||
errDetachBeforeOpened = errors.New("datachannel not opened yet, try calling Detach from OnOpen")
|
||||
errDtlsTransportNotStarted = errors.New("the DTLS transport has not started yet")
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
package webrtc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pion/sdp/v3"
|
||||
)
|
||||
|
||||
@@ -20,6 +22,9 @@ type SessionDescription struct {
|
||||
func (sd *SessionDescription) Unmarshal() (*sdp.SessionDescription, error) {
|
||||
sd.parsed = &sdp.SessionDescription{}
|
||||
err := sd.parsed.UnmarshalString(sd.SDP)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w: %w", ErrSDPUnmarshalling, err)
|
||||
}
|
||||
|
||||
return sd.parsed, err
|
||||
return sd.parsed, nil
|
||||
}
|
||||
|
||||
@@ -85,3 +85,13 @@ func TestSessionDescription_Unmarshal(t *testing.T) {
|
||||
// check if the two parsed results _really_ match, could be affected by internal caching
|
||||
assert.True(t, reflect.DeepEqual(parsed1, parsed2))
|
||||
}
|
||||
|
||||
func TestSessionDescription_UnmarshalError(t *testing.T) {
|
||||
desc := SessionDescription{
|
||||
Type: SDPTypeOffer,
|
||||
SDP: "invalid sdp",
|
||||
}
|
||||
assert.Nil(t, desc.parsed)
|
||||
_, err := desc.Unmarshal()
|
||||
assert.ErrorIs(t, err, ErrSDPUnmarshalling)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user