rings_transport/
error.rs

1#![allow(missing_docs)]
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(thiserror::Error, Debug)]
6pub enum IceServerError {
7    #[error("Url parse error")]
8    UrlParse(#[from] url::ParseError),
9
10    #[error("Ice server scheme {0} has not supported yet")]
11    SchemeNotSupported(String),
12
13    #[error("Cannot extract host from url")]
14    UrlMissHost,
15}
16
17#[derive(thiserror::Error, Debug)]
18pub enum Error {
19    #[error("IO error: {0}")]
20    Io(#[from] std::io::Error),
21
22    #[cfg(feature = "native-webrtc")]
23    #[error("WebRTC error: {0}")]
24    Webrtc(#[from] webrtc::error::Error),
25
26    #[cfg(feature = "web-sys-webrtc")]
27    #[error("WebSysWebRTC error: {}", dump_js_value(.0))]
28    WebSysWebrtc(wasm_bindgen::JsValue),
29
30    #[error("Bincode error: {0}")]
31    Bincode(#[from] bincode::Error),
32
33    #[error("IceServer error: {0}")]
34    IceServer(#[from] IceServerError),
35
36    #[error("Failed when waiting for data channel open: {0}")]
37    DataChannelOpen(String),
38
39    #[error("WebRTC local SDP generation error: {0}")]
40    WebrtcLocalSdpGenerationError(String),
41
42    #[error("Connection {0} already exists")]
43    ConnectionAlreadyExists(String),
44
45    #[error("Connection {0} not found, should handshake first")]
46    ConnectionNotFound(String),
47
48    #[error("Connection {0} is released")]
49    ConnectionReleased(String),
50
51    #[error("Rwlock try write failed: {0}")]
52    RwLockWrite(String),
53
54    #[error("Rwlock try read failed: {0}")]
55    RwLockRead(String),
56}
57
58#[cfg(feature = "web-sys-webrtc")]
59fn dump_js_value(v: &wasm_bindgen::JsValue) -> String {
60    let Ok(s) = js_sys::JSON::stringify(v) else {
61        return "Failed to stringify Error(JsValue)".to_string();
62    };
63    s.into()
64}