Skip to content

Commit ed9f7fa

Browse files
committed
Add an error for sdp unmarshalling error
Add the publicly available ErrSDPUnmarshal error when an sdp unmarshal fails.
1 parent 5552def commit ed9f7fa

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

errors.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ var (
175175
// and the requested SSRC was ignored.
176176
ErrSimulcastProbeOverflow = errors.New("simulcast probe limit has been reached, new SSRC has been discarded")
177177

178+
// ErrSDPUnmarshalling indicates that the SDP could not be unmarshalled.
179+
ErrSDPUnmarshalling = errors.New("failed to unmarshal SDP")
180+
178181
errDetachNotEnabled = errors.New("enable detaching by calling webrtc.DetachDataChannels()")
179182
errDetachBeforeOpened = errors.New("datachannel not opened yet, try calling Detach from OnOpen")
180183
errDtlsTransportNotStarted = errors.New("the DTLS transport has not started yet")

sessiondescription.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package webrtc
55

66
import (
7+
"fmt"
8+
79
"github.com/pion/sdp/v3"
810
)
911

@@ -20,6 +22,9 @@ type SessionDescription struct {
2022
func (sd *SessionDescription) Unmarshal() (*sdp.SessionDescription, error) {
2123
sd.parsed = &sdp.SessionDescription{}
2224
err := sd.parsed.UnmarshalString(sd.SDP)
25+
if err != nil {
26+
return nil, fmt.Errorf("%w: %w", ErrSDPUnmarshalling, err)
27+
}
2328

24-
return sd.parsed, err
29+
return sd.parsed, nil
2530
}

sessiondescription_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,13 @@ func TestSessionDescription_Unmarshal(t *testing.T) {
8585
// check if the two parsed results _really_ match, could be affected by internal caching
8686
assert.True(t, reflect.DeepEqual(parsed1, parsed2))
8787
}
88+
89+
func TestSessionDescription_UnmarshalError(t *testing.T) {
90+
desc := SessionDescription{
91+
Type: SDPTypeOffer,
92+
SDP: "invalid sdp",
93+
}
94+
assert.Nil(t, desc.parsed)
95+
_, err := desc.Unmarshal()
96+
assert.ErrorIs(t, err, ErrSDPUnmarshalling)
97+
}

0 commit comments

Comments
 (0)