Add an error for sdp unmarshalling error

Add the publicly available ErrSDPUnmarshal error
when an sdp unmarshal fails.
This commit is contained in:
Sanan Kornyakov
2025-11-25 00:40:19 +03:00
parent 5552def3bf
commit ed9f7faece
3 changed files with 19 additions and 1 deletions

View File

@@ -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")

View File

@@ -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
}

View File

@@ -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)
}