use std::num::ParseIntError;
use std::time::SystemTimeError;
use std::{io, net};
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Error, PartialEq)]
#[non_exhaustive]
pub enum Error {
#[error("Unknown type")]
ErrUnknownType,
#[error("unknown scheme type")]
ErrSchemeType,
#[error("queries not supported in stun address")]
ErrStunQuery,
#[error("invalid query")]
ErrInvalidQuery,
#[error("invalid hostname")]
ErrHost,
#[error("invalid port number")]
ErrPort,
#[error("local username fragment is less than 24 bits long")]
ErrLocalUfragInsufficientBits,
#[error("local password is less than 128 bits long")]
ErrLocalPwdInsufficientBits,
#[error("invalid transport protocol type")]
ErrProtoType,
#[error("the agent is closed")]
ErrClosed,
#[error("no candidate pairs available")]
ErrNoCandidatePairs,
#[error("connecting canceled by caller")]
ErrCanceledByCaller,
#[error("attempted to start agent twice")]
ErrMultipleStart,
#[error("remote ufrag is empty")]
ErrRemoteUfragEmpty,
#[error("remote pwd is empty")]
ErrRemotePwdEmpty,
#[error("no on_candidate provided")]
ErrNoOnCandidateHandler,
#[error("attempting to gather candidates during gathering state")]
ErrMultipleGatherAttempted,
#[error("username is empty")]
ErrUsernameEmpty,
#[error("password is empty")]
ErrPasswordEmpty,
#[error("failed to parse address")]
ErrAddressParseFailed,
#[error("lite agents must only use host candidates")]
ErrLiteUsingNonHostCandidates,
#[error("agent does not need URL with selected candidate types")]
ErrUselessUrlsProvided,
#[error("unsupported 1:1 NAT IP candidate type")]
ErrUnsupportedNat1to1IpCandidateType,
#[error("invalid 1:1 NAT IP mapping")]
ErrInvalidNat1to1IpMapping,
#[error("external mapped IP not found")]
ErrExternalMappedIpNotFound,
#[error("mDNS gathering cannot be used with 1:1 NAT IP mapping for host candidate")]
ErrMulticastDnsWithNat1to1IpMapping,
#[error("1:1 NAT IP mapping for host candidate ineffective")]
ErrIneffectiveNat1to1IpMappingHost,
#[error("1:1 NAT IP mapping for srflx candidate ineffective")]
ErrIneffectiveNat1to1IpMappingSrflx,
#[error("invalid mDNS HostName, must end with .local and can only contain a single '.'")]
ErrInvalidMulticastDnshostName,
#[error("ICE Agent can not be restarted when gathering")]
ErrRestartWhenGathering,
#[error("run was canceled by done")]
ErrRunCanceled,
#[error("TCPMux is not initialized")]
ErrTcpMuxNotInitialized,
#[error("conn with same remote addr already exists")]
ErrTcpRemoteAddrAlreadyExists,
#[error("failed to send packet")]
ErrSendPacket,
#[error("attribute not long enough to be ICE candidate")]
ErrAttributeTooShortIceCandidate,
#[error("could not parse component")]
ErrParseComponent,
#[error("could not parse priority")]
ErrParsePriority,
#[error("could not parse port")]
ErrParsePort,
#[error("could not parse related addresses")]
ErrParseRelatedAddr,
#[error("could not parse type")]
ErrParseType,
#[error("unknown candidate type")]
ErrUnknownCandidateType,
#[error("failed to get XOR-MAPPED-ADDRESS response")]
ErrGetXorMappedAddrResponse,
#[error("connection with same remote address already exists")]
ErrConnectionAddrAlreadyExist,
#[error("error reading streaming packet")]
ErrReadingStreamingPacket,
#[error("error writing to")]
ErrWriting,
#[error("error closing connection")]
ErrClosingConnection,
#[error("unable to determine networkType")]
ErrDetermineNetworkType,
#[error("missing protocol scheme")]
ErrMissingProtocolScheme,
#[error("too many colons in address")]
ErrTooManyColonsAddr,
#[error("unexpected error trying to read")]
ErrRead,
#[error("unknown role")]
ErrUnknownRole,
#[error("username mismatch")]
ErrMismatchUsername,
#[error("the ICE conn can't write STUN messages")]
ErrIceWriteStunMessage,
#[error("invalid url")]
ErrInvalidUrl,
#[error("relative URL without a base")]
ErrUrlParse,
#[error("Candidate IP could not be found")]
ErrCandidateIpNotFound,
#[error("parse int: {0}")]
ParseInt(#[from] ParseIntError),
#[error("parse addr: {0}")]
ParseIp(#[from] net::AddrParseError),
#[error("{0}")]
Io(#[source] IoError),
#[error("{0}")]
Util(#[from] util::Error),
#[error("{0}")]
Stun(#[from] stun::Error),
#[error("{0}")]
ParseUrl(#[from] url::ParseError),
#[error("{0}")]
Mdns(#[from] mdns::Error),
#[error("{0}")]
Turn(#[from] turn::Error),
#[error("{0}")]
Other(String),
}
#[derive(Debug, Error)]
#[error("io error: {0}")]
pub struct IoError(#[from] pub io::Error);
impl PartialEq for IoError {
fn eq(&self, other: &Self) -> bool {
self.0.kind() == other.0.kind()
}
}
impl From<io::Error> for Error {
fn from(e: io::Error) -> Self {
Error::Io(IoError(e))
}
}
impl From<SystemTimeError> for Error {
fn from(e: SystemTimeError) -> Self {
Error::Other(e.to_string())
}
}