xref: /webrtc/ice/src/error.rs (revision ffe74184)
1 use thiserror::Error;
2 
3 use std::io;
4 use std::net;
5 use std::num::ParseIntError;
6 use std::time::SystemTimeError;
7 
8 pub type Result<T> = std::result::Result<T, Error>;
9 
10 #[derive(Debug, Error, PartialEq)]
11 #[non_exhaustive]
12 pub enum Error {
13     /// Indicates an error with Unknown info.
14     #[error("Unknown type")]
15     ErrUnknownType,
16 
17     /// Indicates the scheme type could not be parsed.
18     #[error("unknown scheme type")]
19     ErrSchemeType,
20 
21     /// Indicates query arguments are provided in a STUN URL.
22     #[error("queries not supported in stun address")]
23     ErrStunQuery,
24 
25     /// Indicates an malformed query is provided.
26     #[error("invalid query")]
27     ErrInvalidQuery,
28 
29     /// Indicates malformed hostname is provided.
30     #[error("invalid hostname")]
31     ErrHost,
32 
33     /// Indicates malformed port is provided.
34     #[error("invalid port number")]
35     ErrPort,
36 
37     /// Indicates local username fragment insufficient bits are provided.
38     /// Have to be at least 24 bits long.
39     #[error("local username fragment is less than 24 bits long")]
40     ErrLocalUfragInsufficientBits,
41 
42     /// Indicates local passoword insufficient bits are provided.
43     /// Have to be at least 128 bits long.
44     #[error("local password is less than 128 bits long")]
45     ErrLocalPwdInsufficientBits,
46 
47     /// Indicates an unsupported transport type was provided.
48     #[error("invalid transport protocol type")]
49     ErrProtoType,
50 
51     /// Indicates the agent is closed.
52     #[error("the agent is closed")]
53     ErrClosed,
54 
55     /// Indicates agent does not have a valid candidate pair.
56     #[error("no candidate pairs available")]
57     ErrNoCandidatePairs,
58 
59     /// Indicates agent connection was canceled by the caller.
60     #[error("connecting canceled by caller")]
61     ErrCanceledByCaller,
62 
63     /// Indicates agent was started twice.
64     #[error("attempted to start agent twice")]
65     ErrMultipleStart,
66 
67     /// Indicates agent was started with an empty remote ufrag.
68     #[error("remote ufrag is empty")]
69     ErrRemoteUfragEmpty,
70 
71     /// Indicates agent was started with an empty remote pwd.
72     #[error("remote pwd is empty")]
73     ErrRemotePwdEmpty,
74 
75     /// Indicates agent was started without on_candidate.
76     #[error("no on_candidate provided")]
77     ErrNoOnCandidateHandler,
78 
79     /// Indicates GatherCandidates has been called multiple times.
80     #[error("attempting to gather candidates during gathering state")]
81     ErrMultipleGatherAttempted,
82 
83     /// Indicates agent was give TURN URL with an empty Username.
84     #[error("username is empty")]
85     ErrUsernameEmpty,
86 
87     /// Indicates agent was give TURN URL with an empty Password.
88     #[error("password is empty")]
89     ErrPasswordEmpty,
90 
91     /// Indicates we were unable to parse a candidate address.
92     #[error("failed to parse address")]
93     ErrAddressParseFailed,
94 
95     /// Indicates that non host candidates were selected for a lite agent.
96     #[error("lite agents must only use host candidates")]
97     ErrLiteUsingNonHostCandidates,
98 
99     /// Indicates that one or more URL was provided to the agent but no host candidate required them.
100     #[error("agent does not need URL with selected candidate types")]
101     ErrUselessUrlsProvided,
102 
103     /// Indicates that the specified NAT1To1IPCandidateType is unsupported.
104     #[error("unsupported 1:1 NAT IP candidate type")]
105     ErrUnsupportedNat1to1IpCandidateType,
106 
107     /// Indicates that the given 1:1 NAT IP mapping is invalid.
108     #[error("invalid 1:1 NAT IP mapping")]
109     ErrInvalidNat1to1IpMapping,
110 
111     /// IPNotFound in NAT1To1IPMapping.
112     #[error("external mapped IP not found")]
113     ErrExternalMappedIpNotFound,
114 
115     /// Indicates that the mDNS gathering cannot be used along with 1:1 NAT IP mapping for host
116     /// candidate.
117     #[error("mDNS gathering cannot be used with 1:1 NAT IP mapping for host candidate")]
118     ErrMulticastDnsWithNat1to1IpMapping,
119 
120     /// Indicates that 1:1 NAT IP mapping for host candidate is requested, but the host candidate
121     /// type is disabled.
122     #[error("1:1 NAT IP mapping for host candidate ineffective")]
123     ErrIneffectiveNat1to1IpMappingHost,
124 
125     /// Indicates that 1:1 NAT IP mapping for srflx candidate is requested, but the srflx candidate
126     /// type is disabled.
127     #[error("1:1 NAT IP mapping for srflx candidate ineffective")]
128     ErrIneffectiveNat1to1IpMappingSrflx,
129 
130     /// Indicates an invalid MulticastDNSHostName.
131     #[error("invalid mDNS HostName, must end with .local and can only contain a single '.'")]
132     ErrInvalidMulticastDnshostName,
133 
134     /// Indicates Restart was called when Agent is in GatheringStateGathering.
135     #[error("ICE Agent can not be restarted when gathering")]
136     ErrRestartWhenGathering,
137 
138     /// Indicates a run operation was canceled by its individual done.
139     #[error("run was canceled by done")]
140     ErrRunCanceled,
141 
142     /// Initialized Indicates TCPMux is not initialized and that invalidTCPMux is used.
143     #[error("TCPMux is not initialized")]
144     ErrTcpMuxNotInitialized,
145 
146     /// Indicates we already have the connection with same remote addr.
147     #[error("conn with same remote addr already exists")]
148     ErrTcpRemoteAddrAlreadyExists,
149 
150     #[error("failed to send packet")]
151     ErrSendPacket,
152     #[error("attribute not long enough to be ICE candidate")]
153     ErrAttributeTooShortIceCandidate,
154     #[error("could not parse component")]
155     ErrParseComponent,
156     #[error("could not parse priority")]
157     ErrParsePriority,
158     #[error("could not parse port")]
159     ErrParsePort,
160     #[error("could not parse related addresses")]
161     ErrParseRelatedAddr,
162     #[error("could not parse type")]
163     ErrParseType,
164     #[error("unknown candidate type")]
165     ErrUnknownCandidateType,
166     #[error("failed to get XOR-MAPPED-ADDRESS response")]
167     ErrGetXorMappedAddrResponse,
168     #[error("connection with same remote address already exists")]
169     ErrConnectionAddrAlreadyExist,
170     #[error("error reading streaming packet")]
171     ErrReadingStreamingPacket,
172     #[error("error writing to")]
173     ErrWriting,
174     #[error("error closing connection")]
175     ErrClosingConnection,
176     #[error("unable to determine networkType")]
177     ErrDetermineNetworkType,
178     #[error("missing protocol scheme")]
179     ErrMissingProtocolScheme,
180     #[error("too many colons in address")]
181     ErrTooManyColonsAddr,
182     #[error("unexpected error trying to read")]
183     ErrRead,
184     #[error("unknown role")]
185     ErrUnknownRole,
186     #[error("username mismatch")]
187     ErrMismatchUsername,
188     #[error("the ICE conn can't write STUN messages")]
189     ErrIceWriteStunMessage,
190     #[error("invalid url")]
191     ErrInvalidUrl,
192     #[error("relative URL without a base")]
193     ErrUrlParse,
194     #[error("Candidate IP could not be found")]
195     ErrCandidateIpNotFound,
196 
197     #[error("parse int: {0}")]
198     ParseInt(#[from] ParseIntError),
199     #[error("parse addr: {0}")]
200     ParseIp(#[from] net::AddrParseError),
201     #[error("{0}")]
202     Io(#[source] IoError),
203     #[error("{0}")]
204     Util(#[from] util::Error),
205     #[error("{0}")]
206     Stun(#[from] stun::Error),
207     #[error("{0}")]
208     ParseUrl(#[from] url::ParseError),
209     #[error("{0}")]
210     Mdns(#[from] mdns::Error),
211     #[error("{0}")]
212     Turn(#[from] turn::Error),
213 
214     #[error("{0}")]
215     Other(String),
216 }
217 
218 #[derive(Debug, Error)]
219 #[error("io error: {0}")]
220 pub struct IoError(#[from] pub io::Error);
221 
222 // Workaround for wanting PartialEq for io::Error.
223 impl PartialEq for IoError {
eq(&self, other: &Self) -> bool224     fn eq(&self, other: &Self) -> bool {
225         self.0.kind() == other.0.kind()
226     }
227 }
228 
229 impl From<io::Error> for Error {
from(e: io::Error) -> Self230     fn from(e: io::Error) -> Self {
231         Error::Io(IoError(e))
232     }
233 }
234 
235 impl From<SystemTimeError> for Error {
from(e: SystemTimeError) -> Self236     fn from(e: SystemTimeError) -> Self {
237         Error::Other(e.to_string())
238     }
239 }
240