webrtc_unreliable_client/webrtc/crates/stun/
error.rs1use thiserror::Error;
2
3use std::io;
4use std::string::FromUtf8Error;
5use tokio::sync::mpsc::error::SendError as MpscSendError;
6
7pub(crate) type Result<T> = std::result::Result<T, Error>;
8
9#[derive(Debug, Error, PartialEq)]
10#[non_exhaustive]
11pub(crate) enum Error {
12 #[error("attribute not found")]
13 ErrAttributeNotFound,
14 #[error("no default reason for ErrorCode")]
15 ErrNoDefaultReason,
16 #[error("unexpected EOF")]
17 ErrUnexpectedEof,
18 #[error("attribute size is invalid")]
19 ErrAttributeSizeInvalid,
20 #[error("attribute size overflow")]
21 ErrAttributeSizeOverflow,
22 #[error("unexpected EOF: not enough bytes to read header")]
23 ErrUnexpectedHeaderEof,
24 #[error("integrity check failed")]
25 ErrIntegrityMismatch,
26 #[error("FINGERPRINT before MESSAGE-INTEGRITY attribute")]
27 ErrFingerprintBeforeIntegrity,
28 #[error("{0}")]
29 Other(String),
30 #[error("url parse: {0}")]
31 Url(#[from] url::ParseError),
32 #[error("utf8: {0}")]
33 Utf8(#[from] FromUtf8Error),
34 #[error("{0}")]
35 Io(#[source] IoError),
36 #[error("mpsc send: {0}")]
37 MpscSend(String),
38 #[error("{0}")]
39 Util(#[from] crate::webrtc::util::Error),
40}
41
42#[derive(Debug, Error)]
43#[error("io error: {0}")]
44pub(crate) struct IoError(#[from] pub(crate) io::Error);
45
46impl PartialEq for IoError {
48 fn eq(&self, other: &Self) -> bool {
49 self.0.kind() == other.0.kind()
50 }
51}
52
53impl From<io::Error> for Error {
54 fn from(e: io::Error) -> Self {
55 Error::Io(IoError(e))
56 }
57}
58
59impl<T> From<MpscSendError<T>> for Error {
61 fn from(e: MpscSendError<T>) -> Self {
62 Error::MpscSend(e.to_string())
63 }
64}