webrtc icon indicating copy to clipboard operation
webrtc copied to clipboard

Strange enum Error

Open MariaGolubev opened this issue 3 years ago • 1 comments

Error contains new(String) - This is bad code!!!!!

i get such an error:

>> new("io error: Conn is closed")

i expected to get: Error::ErrConnectionClosed

I get this error when I try to write a packet to the track:

while let Some(sample) = appsink_stream.next().await {
            if let Some(buffer) = sample.buffer() {
                if let Ok(map) = buffer.map_readable() {
                    let slice = map.as_slice();

                    if let Err(err) = video_track_clone.write(slice).await {
                        match err {
                            webrtc::Error::ErrConnectionClosed => continue,
                            webrtc::Error::ErrClosedPipe => break,
                            err => {
                                tracing::error!("video_track write err: {err}");
                                break;
                            }
                        }
                    }
                } else {
                    break;
                }
            } else {
                break;
            }
        }

I am using Arc<TrackLocalStaticRTP> in several RTCPeerConnection The error appears when closing several RTCPeerConnection

MariaGolubev avatar Mar 15 '22 10:03 MariaGolubev

I suspect it was ported when @algesten moved the error type from anyhow to thiserror, anyhow is more stringly typed.

I think the way forward here is to start converting the errors that use the new variant to bespoke variants.

PRs that do this are welcome I expect

k0nserv avatar Apr 14 '22 17:04 k0nserv