tor_error/lib.rs
1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![doc = include_str!("../README.md")]
3// @@ begin lint list maintained by maint/add_warning @@
4#![allow(renamed_and_removed_lints)] // @@REMOVE_WHEN(ci_arti_stable)
5#![allow(unknown_lints)] // @@REMOVE_WHEN(ci_arti_nightly)
6#![warn(missing_docs)]
7#![warn(noop_method_call)]
8#![warn(unreachable_pub)]
9#![warn(clippy::all)]
10#![deny(clippy::await_holding_lock)]
11#![deny(clippy::cargo_common_metadata)]
12#![deny(clippy::cast_lossless)]
13#![deny(clippy::checked_conversions)]
14#![warn(clippy::cognitive_complexity)]
15#![deny(clippy::debug_assert_with_mut_call)]
16#![deny(clippy::exhaustive_enums)]
17#![deny(clippy::exhaustive_structs)]
18#![deny(clippy::expl_impl_clone_on_copy)]
19#![deny(clippy::fallible_impl_from)]
20#![deny(clippy::implicit_clone)]
21#![deny(clippy::large_stack_arrays)]
22#![warn(clippy::manual_ok_or)]
23#![deny(clippy::missing_docs_in_private_items)]
24#![warn(clippy::needless_borrow)]
25#![warn(clippy::needless_pass_by_value)]
26#![warn(clippy::option_option)]
27#![deny(clippy::print_stderr)]
28#![deny(clippy::print_stdout)]
29#![warn(clippy::rc_buffer)]
30#![deny(clippy::ref_option_ref)]
31#![warn(clippy::semicolon_if_nothing_returned)]
32#![warn(clippy::trait_duplication_in_bounds)]
33#![deny(clippy::unchecked_time_subtraction)]
34#![deny(clippy::unnecessary_wraps)]
35#![warn(clippy::unseparated_literal_suffix)]
36#![deny(clippy::unwrap_used)]
37#![deny(clippy::mod_module_files)]
38#![allow(clippy::let_unit_value)] // This can reasonably be done for explicitness
39#![allow(clippy::uninlined_format_args)]
40#![allow(clippy::significant_drop_in_scrutinee)] // arti/-/merge_requests/588/#note_2812945
41#![allow(clippy::result_large_err)] // temporary workaround for arti#587
42#![allow(clippy::needless_raw_string_hashes)] // complained-about code is fine, often best
43#![allow(clippy::needless_lifetimes)] // See arti#1765
44#![allow(mismatched_lifetime_syntaxes)] // temporary workaround for arti#2060
45#![allow(clippy::collapsible_if)] // See arti#2342
46#![deny(clippy::unused_async)]
47#![deny(clippy::string_slice)] // See arti#2571
48//! <!-- @@ end lint list maintained by maint/add_warning @@ -->
49
50use derive_more::Display;
51
52mod internal;
53pub use internal::*;
54
55mod report;
56pub use report::*;
57
58mod retriable;
59pub use retriable::*;
60
61mod misc;
62pub use misc::*;
63
64#[cfg(feature = "tracing")]
65pub mod tracing;
66
67#[cfg(feature = "http")]
68mod http;
69
70/// Classification of an error arising from Arti's Tor operations
71///
72/// This `ErrorKind` should suffice for programmatic handling by most applications embedding Arti:
73/// get the kind via [`HasKind::kind`] and compare it to the expected value(s) with equality
74/// or by matching.
75///
76/// When forwarding or reporting errors, use the whole error (e.g., `TorError`), not just the kind:
77/// the error itself will contain more detail and context which is useful to humans.
78//
79// Splitting vs lumping guidelines:
80//
81// # Split on the place which caused the error
82//
83// Every ErrorKind should generally have an associated "location" in
84// which it occurred. If a problem can happen in two different
85// "locations", it should have two different ErrorKinds. (This goal
86// may be frustrated sometimes by difficulty in determining where exactly
87// a given error occurred.)
88//
89// The location of an ErrorKind should always be clear from its name. If is not
90// clear, add a location-related word to the name of the ErrorKind.
91//
92// For the purposes of this discussion, the following locations exist:
93// - Process: Our code, or the application code using it. These errors don't
94// usually need a special prefix.
95// - Host: A problem with our local computing environment. These errors
96// usually reflect trying to run under impossible circumstances (no file
97// system, no permissions, etc).
98// - Local: Another process on the same machine, or on the network between us
99// and the Tor network. Errors in this location often indicate an outage,
100// misconfiguration, or a censorship event.
101// - Tor: Anywhere within the Tor network, or connections between Tor relays.
102// The words "Exit" and "Relay" also indicate this location.
103// - Remote: Anywhere _beyond_ the Tor exit. Can be a problem in the Tor
104// exit's connection to the real internet, or with the remote host that the
105// exit is talking to. (This kind of error can also indicate that the exit
106// is lying.)
107//
108// ## Lump any locations more fine-grained than that.
109//
110// We do not split locations more finely unless there's a good reason to do so.
111// For example, we don't typically split errors within the "Tor" location based
112// on whether they happened at a guard, a directory, or an exit. (Errors with
113// "Exit" or "Guard" in their names are okay, so long as that kind of error can
114// _only_ occur at an Exit or Guard.)
115//
116// # Split based on reasonable response and semantics
117//
118// We also should split ErrorKinds based on what it's reasonable for the
119// receiver to do with them. Users may find more applications for our errors
120// than we do, so we shouldn't assume that we can predict every reasonable use
121// in advance.
122//
123// ErrorKinds should be more specific than just the locations in which they
124// happen: for example, there shouldn't be a `TorNetworkError` or
125// a `RemoteFailure`.
126//
127// # Avoid exposing implementation details
128//
129// ErrorKinds should not relate to particular code paths in the Arti codebase.
130
131#[derive(Debug, Clone, Copy, PartialEq, Eq, Display)]
132#[non_exhaustive]
133pub enum ErrorKind {
134 /// Error connecting to the Tor network
135 ///
136 /// Perhaps the local network is not working,
137 /// or perhaps the chosen relay or bridge is not working properly.
138 /// Not used for errors that occur within the Tor network, or accessing the public
139 /// internet on the far side of Tor.
140 #[display("error connecting to Tor")]
141 TorAccessFailed,
142
143 /// An attempt was made to use a Tor client for something without bootstrapping it first.
144 #[display("attempted to use unbootstrapped client")]
145 BootstrapRequired,
146
147 /// Our network directory has expired before we were able to replace it.
148 ///
149 /// This kind of error can indicate one of several possible problems:
150 /// * It can occur if the client used to be on the network, but has been
151 /// unable to make directory connections for a while.
152 /// * It can occur if the client has been suspended or sleeping for a long
153 /// time, and has suddenly woken up without having a chance to replace its
154 /// network directory.
155 /// * It can happen if the client has a sudden clock jump.
156 ///
157 /// Often, retrying after a minute or so will resolve this issue.
158 ///
159 // TODO this is pretty shonky. "try again after a minute or so", seriously?
160 //
161 /// Future versions of Arti may resolve this situation automatically without caller
162 /// intervention, possibly depending on preferences and API usage, in which case this kind of
163 /// error will never occur.
164 //
165 // TODO: We should distinguish among the actual issues here, and report a
166 // real bootstrapping problem when it exists.
167 #[display("network directory is expired.")]
168 DirectoryExpired,
169
170 /// IO error accessing local persistent state
171 ///
172 /// For example, the disk might be full, or there may be a permissions problem.
173 /// Usually the source will be [`std::io::Error`].
174 ///
175 /// Note that this kind of error only applies to problems in your `state_dir`:
176 /// problems with your cache are another kind.
177 #[display("could not read/write persistent state")]
178 PersistentStateAccessFailed,
179
180 /// We could not start up because a local resource is already being used by someone else
181 ///
182 /// Local resources include things like listening ports and state lockfiles.
183 /// (We don't use this error for "out of disk space" and the like.)
184 ///
185 /// This can occur when another process
186 /// (or another caller of Arti APIs)
187 /// is already running a facility that overlaps with the one being requested.
188 ///
189 /// For example,
190 /// running multiple processes each containing instances of the same hidden service,
191 /// using the same state directories etc., is not supported.
192 ///
193 /// Another example:
194 /// if Arti is configured to listen on a particular port,
195 /// but another process on the system is already listening there,
196 /// the resulting error has kind `LocalResourceAlreadyInUse`.
197 // Actually, we only currently listen on ports in `arti` so we don't return
198 // any Rust errors for this situation at all, at the time of writing.
199 #[display("local resource (port, lockfile, etc.) already in use")]
200 LocalResourceAlreadyInUse,
201
202 /// We encountered a problem with filesystem permissions.
203 ///
204 /// This is likeliest to be caused by permissions on a file or directory
205 /// being too permissive; the next likeliest cause is that we were unable to
206 /// check the permissions on the file or directory, or on one of its
207 /// ancestors.
208 #[display("problem with filesystem permissions")]
209 FsPermissions,
210
211 /// Tor client's persistent state has been corrupted
212 ///
213 /// This could be because of a bug in the Tor code, or because something
214 /// else has been messing with the data.
215 ///
216 /// This might also occur if the Tor code was upgraded and the new Tor is
217 /// not compatible.
218 ///
219 /// Note that this kind of error only applies to problems in your
220 /// `state_dir`: problems with your cache are another kind.
221 #[display("corrupted data in persistent state")]
222 PersistentStateCorrupted,
223
224 /// Tor client's cache has been corrupted.
225 ///
226 /// This could be because of a bug in the Tor code, or because something else has been messing
227 /// with the data.
228 ///
229 /// This might also occur if the Tor code was upgraded and the new Tor is not compatible.
230 ///
231 /// Note that this kind of error only applies to problems in your `cache_dir`:
232 /// problems with your persistent state are another kind.
233 #[display("corrupted data in cache")]
234 CacheCorrupted,
235
236 /// We had a problem reading or writing to our data cache.
237 ///
238 /// This may be a disk error, a file permission error, or similar.
239 ///
240 /// Note that this kind of error only applies to problems in your `cache_dir`:
241 /// problems with your persistent state are another kind.
242 #[display("cache access problem")]
243 CacheAccessFailed,
244
245 /// The keystore has been corrupted
246 ///
247 /// This could be because of a bug in the Tor code, or because something else has been messing
248 /// with the data.
249 ///
250 /// Note that this kind of error only applies to problems in your `keystore_dir`:
251 /// problems with your cache or persistent state are another kind.
252 #[display("corrupted data in keystore")]
253 KeystoreCorrupted,
254
255 /// IO error accessing keystore
256 ///
257 /// For example, the disk might be full, or there may be a permissions problem.
258 /// The source is typically an [`std::io::Error`].
259 ///
260 /// Note that this kind of error only applies to problems in your `keystore_dir`:
261 /// problems with your cache or persistent state are another kind.
262 #[display("could not access keystore")]
263 KeystoreAccessFailed,
264
265 /// Tor client's Rust async reactor is shutting down.
266 ///
267 /// This likely indicates that the reactor has encountered a fatal error, or
268 /// has been told to do a clean shutdown, and it isn't possible to spawn new
269 /// tasks.
270 #[display("reactor is shutting down")]
271 ReactorShuttingDown,
272
273 /// Tor client is shutting down.
274 ///
275 /// This likely indicates that the last handle to the `TorClient` has been
276 /// dropped, and is preventing other operations from completing.
277 #[display("Tor client is shutting down.")]
278 ArtiShuttingDown,
279
280 /// This Tor client software is missing some feature that is recommended
281 /// (or required) for operation on the network.
282 ///
283 /// This occurs when the directory authorities tell us that we ought to have
284 /// a particular protocol feature that we do not support.
285 /// The correct solution is likely to upgrade to a more recent version of Arti.
286 #[display("Software version is deprecated")]
287 SoftwareDeprecated,
288
289 /// An operation failed because we waited too long for an exit to do
290 /// something.
291 ///
292 /// This error can happen if the host you're trying to connect to isn't
293 /// responding to traffic.
294 /// It can also happen if an exit, or hidden service, is overloaded, and
295 /// unable to answer your replies in a timely manner.
296 ///
297 /// And it might simply mean that the Tor network itself
298 /// (including possibly relays, or hidden service introduction or rendezvous points)
299 /// is not working properly
300 ///
301 /// In either case, trying later, or on a different circuit, might help.
302 //
303 // TODO: Say that this is distinct from the case where the exit _tells you_
304 // that there is a timeout.
305 #[display("operation timed out at exit")]
306 RemoteNetworkTimeout,
307
308 /// One or more configuration values were invalid or incompatible.
309 ///
310 /// This kind of error can happen if the user provides an invalid or badly
311 /// formatted configuration file, if some of the options in that file are
312 /// out of their ranges or unparsable, or if the options are not all
313 /// compatible with one another. It can also happen if configuration options
314 /// provided via APIs are out of range.
315 ///
316 /// If this occurs because of user configuration, it's probably best to tell
317 /// the user about the error. If it occurs because of API usage, it's
318 /// probably best to fix the code that causes the error.
319 #[display("invalid configuration")]
320 InvalidConfig,
321
322 /// Tried to change the configuration of a running Arti service in a way
323 /// that isn't supported.
324 ///
325 /// This kind of error can happen when you call a `reconfigure()` method on
326 /// a service (or part of a service) and the new configuration is not
327 /// compatible with the previous configuration.
328 ///
329 /// The only available remedy is to tear down the service and make a fresh
330 /// one (for example, by making a new `TorClient`).
331 #[display("invalid configuration transition")]
332 InvalidConfigTransition,
333
334 /// Tried to look up a directory depending on the user's home directory, but
335 /// the user's home directory isn't set or can't be found.
336 ///
337 /// This kind of error can also occur if we're running in an environment
338 /// where users don't have home directories.
339 ///
340 /// To resolve this kind of error, either move to an OS with home
341 /// directories, or make sure that all paths in the configuration are set
342 /// explicitly, and do not depend on any path variables.
343 #[display("could not find a home directory")]
344 NoHomeDirectory,
345
346 /// A requested operation was not implemented by Arti.
347 ///
348 /// This kind of error can happen when requesting a piece of protocol
349 /// functionality that has not (yet) been implemented in the Arti project.
350 ///
351 /// If it happens as a result of a user activity, it's fine to ignore, log,
352 /// or report the error. If it happens as a result of direct API usage, it
353 /// may indicate that you're using something that isn't implemented yet.
354 ///
355 /// This kind can relate both to operations which we plan to implement, and
356 /// to operations which we do not. It does not relate to facilities which
357 /// are disabled (e.g. at build time) or harmful.
358 ///
359 /// It can refer to facilities which were once implemented in Tor or Arti
360 /// but for which support has been removed.
361 #[display("operation not implemented")]
362 NotImplemented,
363
364 /// A feature was requested which has been disabled in this build of Arti.
365 ///
366 /// This kind of error happens when the running Arti was built without the
367 /// appropriate feature (usually, cargo feature) enabled.
368 ///
369 /// This might indicate that the overall running system has been
370 /// mis-configured at build-time. Alternatively, it can occur if the
371 /// running system is deliberately stripped down, in which case it might be
372 /// reasonable to simply report this error to a user.
373 #[display("operation not supported because Arti feature disabled")]
374 FeatureDisabled,
375
376 /// Someone or something local violated a network protocol.
377 ///
378 /// This kind of error can happen when a local program accessing us over some
379 /// other protocol violates the protocol's requirements.
380 ///
381 /// This usually indicates a programming error: either in that program's
382 /// implementation of the protocol, or in ours. In any case, the problem
383 /// is with software on the local system (or otherwise sharing a Tor client).
384 ///
385 /// It might also occur if the local system has an incompatible combination
386 /// of tools that we can't talk with.
387 ///
388 /// This error kind does *not* include situations that are better explained
389 /// by a local program simply crashing or terminating unexpectedly.
390 #[display("local protocol violation (local bug or incompatibility)")]
391 LocalProtocolViolation,
392
393 /// Someone or something on the Tor network violated the Tor protocols.
394 ///
395 /// This kind of error can happen when a remote Tor instance behaves in a
396 /// way we don't expect.
397 ///
398 /// It usually indicates a programming error: either in their implementation
399 /// of the protocol, or in ours. It can also indicate an attempted attack,
400 /// though that can be hard to diagnose.
401 #[display("Tor network protocol violation (bug, incompatibility, or attack)")]
402 TorProtocolViolation,
403
404 /// Something went wrong with a network connection or the local network.
405 ///
406 /// This kind of error is usually safe to retry, and shouldn't typically be
407 /// seen. By the time it reaches the caller, a more specific error type
408 /// should typically be available.
409 #[display("problem with network or connection")]
410 LocalNetworkError,
411
412 /// More of a local resource was needed, than is available (or than we are allowed)
413 ///
414 /// For example, we tried to use more memory than permitted by our memory quota.
415 #[display("local resource exhausted")]
416 LocalResourceExhausted,
417
418 /// A problem occurred when launching or communicating with an external
419 /// process running on this computer.
420 #[display("an externally launched plug-in tool failed")]
421 ExternalToolFailed,
422
423 /// A relay had an identity other than the one we expected.
424 ///
425 /// This could indicate a MITM attack, but more likely indicates that the
426 /// relay has changed its identity but the new identity hasn't propagated
427 /// through the directory system yet.
428 #[display("identity mismatch")]
429 RelayIdMismatch,
430
431 /// An attempt to do something remotely through the Tor network failed
432 /// because the circuit it was using shut down before the operation could
433 /// finish.
434 #[display("circuit collapsed")]
435 CircuitCollapse,
436
437 /// An operation timed out on the tor network.
438 ///
439 /// This may indicate a network problem, either with the local network
440 /// environment's ability to contact the Tor network, or with the Tor
441 /// network itself.
442 #[display("tor operation timed out")]
443 TorNetworkTimeout,
444
445 /// We tried but failed to download or upload a piece of directory information.
446 ///
447 /// This is a lower-level kind of error; in general it should be retried
448 /// before the user can see it. In the future it is likely to be split
449 /// into several other kinds.
450 // TODO ^
451 #[display("directory fetch or upload attempt failed")]
452 TorDirectoryError,
453
454 /// An operation finished because a remote stream was closed successfully.
455 ///
456 /// This can indicate that the target server closed the TCP connection,
457 /// or that the exit told us that it closed the TCP connection.
458 /// Callers should generally treat this like a closed TCP connection.
459 #[display("remote stream closed")]
460 RemoteStreamClosed,
461
462 /// An operation finished because the remote stream was closed abruptly.
463 ///
464 /// This kind of error is analogous to an ECONNRESET error; it indicates
465 /// that the exit reported that the stream was terminated without a clean
466 /// TCP shutdown.
467 ///
468 /// For most purposes, it's fine to treat this kind of error the same as
469 /// regular unexpected close.
470 #[display("remote stream reset")]
471 RemoteStreamReset,
472
473 /// An operation finished because a remote stream was closed unsuccessfully.
474 ///
475 /// This indicates that the exit reported some error message for the stream.
476 ///
477 /// We only provide this error kind when no more specific kind is available.
478 #[display("remote stream error")]
479 RemoteStreamError,
480
481 /// A stream failed, and the exit reports that the remote host refused
482 /// the connection.
483 ///
484 /// This is analogous to an ECONNREFUSED error.
485 #[display("remote host refused connection")]
486 RemoteConnectionRefused,
487
488 /// A stream was rejected by the exit relay because of that relay's exit
489 /// policy.
490 ///
491 /// (In Tor, exits have a set of policies declaring which addresses and
492 /// ports they're willing to connect to. Clients download only _summaries_
493 /// of these policies, so it's possible to be surprised by an exit's refusal
494 /// to connect somewhere.)
495 #[display("rejected by exit policy")]
496 ExitPolicyRejected,
497
498 /// An operation failed, and the exit reported that it waited too long for
499 /// the operation to finish.
500 ///
501 /// This kind of error is distinct from `RemoteNetworkTimeout`, which means
502 /// that _our own_ timeout threshold was violated.
503 #[display("timeout at exit relay")]
504 ExitTimeout,
505
506 /// An operation failed, and the exit reported a network failure of some
507 /// kind.
508 ///
509 /// This kind of error can occur for a number of reasons. If it happens
510 /// when trying to open a stream, it usually indicates a problem connecting,
511 /// such as an ENOROUTE error.
512 #[display("network failure at exit")]
513 RemoteNetworkFailed,
514
515 /// An operation finished because an exit failed to look up a hostname.
516 ///
517 /// Unfortunately, the Tor protocol does not distinguish failure of DNS
518 /// services ("we couldn't find out if this host exists and what its name is")
519 /// from confirmed denials ("this is not a hostname"). So this kind
520 /// conflates both those sorts of error.
521 ///
522 /// Trying at another exit might succeed, or the address might truly be
523 /// unresolvable.
524 #[display("remote hostname not found")]
525 RemoteHostNotFound,
526
527 /// The target hidden service (`.onion` service) was not found in the directory
528 ///
529 /// We successfully connected to at least one directory server,
530 /// but it didn't have a record of the hidden service.
531 ///
532 /// This probably means that the hidden service is not running, or does not exist.
533 /// (It might mean that the directory servers are faulty,
534 /// and that the hidden service was unable to publish its descriptor.)
535 #[display("Onion Service not found")]
536 OnionServiceNotFound,
537
538 /// The target hidden service (`.onion` service) seems to be down
539 ///
540 /// We successfully obtained a hidden service descriptor for the service,
541 /// so we know it is supposed to exist,
542 /// but we weren't able to communicate with it via any of its
543 /// introduction points.
544 ///
545 /// This probably means that the hidden service is not running.
546 /// (It might mean that the introduction point relays are faulty.)
547 #[display("Onion Service not running")]
548 OnionServiceNotRunning,
549
550 /// Protocol trouble involving the target hidden service (`.onion` service)
551 ///
552 /// Something unexpected happened when trying to connect to the selected hidden service.
553 /// It seems to have been due to the hidden service violating the Tor protocols somehow.
554 #[display("Onion Service protocol failed (apparently due to service behaviour)")]
555 OnionServiceProtocolViolation,
556
557 /// The target hidden service (`.onion` service) is running but we couldn't connect to it,
558 /// and we aren't sure whose fault that is
559 ///
560 /// This might be due to malfunction on the part of the service,
561 /// or a relay being used as an introduction point or relay,
562 /// or failure of the underlying Tor network.
563 #[display("Onion Service not reachable (due to service, or Tor network, behaviour)")]
564 OnionServiceConnectionFailed,
565
566 /// We tried to connect to an onion service without authentication,
567 /// but it apparently requires authentication.
568 #[display("Onion service required authentication, but none was provided.")]
569 OnionServiceMissingClientAuth,
570
571 /// We tried to connect to an onion service that requires authentication, and
572 /// ours is wrong.
573 ///
574 /// This likely means that we need to use a different key for talking to
575 /// this onion service, or that it has revoked our permissions to reach it.
576 #[display("Onion service required authentication, but provided authentication was incorrect.")]
577 OnionServiceWrongClientAuth,
578
579 /// We tried to parse a `.onion` address, and found that it was not valid.
580 ///
581 /// This likely means that it was corrupted somewhere along its way from its
582 /// origin to our API surface. It may be the wrong length, have invalid
583 /// characters, have an invalid version number, or have an invalid checksum.
584 #[display(".onion address was invalid.")]
585 OnionServiceAddressInvalid,
586
587 /// An resolve operation finished with an error.
588 ///
589 /// Contrary to [`RemoteHostNotFound`](ErrorKind::RemoteHostNotFound),
590 /// this can't mean "this is not a hostname".
591 /// This error should be retried.
592 #[display("remote hostname lookup failure")]
593 RemoteHostResolutionFailed,
594
595 /// Trouble involving a protocol we're using with a peer on the far side of the Tor network
596 ///
597 /// We were using a higher-layer protocol over a Tor connection,
598 /// and something went wrong.
599 /// This might be an error reported by the remote host within that higher protocol,
600 /// or a problem detected locally but relating to that higher protocol.
601 ///
602 /// The nature of the problem can vary:
603 /// examples could include:
604 /// failure to agree suitable parameters (incompatibility);
605 /// authentication problems (eg, TLS certificate trouble);
606 /// protocol violation by the peer;
607 /// peer refusing to provide service;
608 /// etc.
609 #[display("remote protocol violation")]
610 RemoteProtocolViolation,
611
612 /// An operation failed, and the relay in question reported that it's too
613 /// busy to answer our request.
614 #[display("relay too busy")]
615 RelayTooBusy,
616
617 /// We were asked to make an anonymous connection to a malformed address.
618 ///
619 /// This is probably because of a bad input from a user.
620 #[display("target address was invalid")]
621 InvalidStreamTarget,
622
623 /// We were asked to make an anonymous connection to a _locally_ disabled
624 /// address.
625 ///
626 /// For example, this kind of error can happen when try to connect to (e.g.)
627 /// `127.0.0.1` using a client that isn't configured with allow_local_addrs.
628 ///
629 /// Usually this means that you intended to reject the request as
630 /// nonsensical; but if you didn't, it probably means you should change your
631 /// configuration to allow what you want.
632 #[display("target address disabled locally")]
633 ForbiddenStreamTarget,
634
635 /// An operation failed in a transient way.
636 ///
637 /// This kind of error indicates that some kind of operation failed in a way
638 /// where retrying it again could likely have made it work.
639 ///
640 /// You should not generally see this kind of error returned directly to you
641 /// for high-level functions. It should only be returned from lower-level
642 /// crates that do not automatically retry these failures.
643 // Errors with this kind should generally not return a `HasRetryTime::retry_time()` of `Never`.
644 #[display("un-retried transient failure")]
645 TransientFailure,
646
647 /// Bug, for example calling a function with an invalid argument.
648 ///
649 /// This kind of error is usually a programming mistake on the caller's part.
650 /// This is usually a bug in code calling Arti, but it might be a bug in Arti itself.
651 //
652 // Usually, use `bad_api_usage!` and `into_bad_api_usage!` and thereby `InternalError`,
653 // rather than inventing a new type with this kind.
654 //
655 // Errors with this kind should generally include a stack trace. They are
656 // very like InternalError, in that they represent a bug in the program.
657 // The difference is that an InternalError, with kind `Internal`, represents
658 // a bug in arti, whereas errors with kind BadArgument represent bugs which
659 // could be (often, are likely to be) outside arti.
660 #[display("bad API usage (bug)")]
661 BadApiUsage,
662
663 /// We asked a relay to create or extend a circuit, and it declined.
664 ///
665 /// Either it gave an error message indicating that it refused to perform
666 /// the request, or the protocol gives it no room to explain what happened.
667 ///
668 /// This error is returned by higher-level functions only if it is the most informative
669 /// error after appropriate retries etc.
670 #[display("remote host refused our request")]
671 CircuitRefused,
672
673 /// We were unable to construct a path through the Tor network.
674 ///
675 /// Usually this indicates that there are too many user-supplied
676 /// restrictions for us to comply with.
677 ///
678 /// On test networks, it likely indicates that there aren't enough relays,
679 /// or that there aren't enough relays in distinct families.
680 //
681 // TODO: in the future, errors of this type should distinguish between
682 // cases where this happens because of a user restriction and cases where it
683 // happens because of a severely broken directory.
684 //
685 // The latter should be classified as TorDirectoryBroken.
686 #[display("could not construct a path")]
687 NoPath,
688
689 /// We were unable to find an exit relay with a certain set of desired
690 /// properties.
691 ///
692 /// Usually this indicates that there were too many user-supplied
693 /// restrictions on the exit for us to comply with, or that there was no
694 /// exit on the network supporting all of the ports that the user asked for.
695 //
696 // TODO: same as for NoPath.
697 #[display("no exit available for path")]
698 NoExit,
699
700 /// The Tor consensus directory is broken or unsuitable
701 ///
702 /// This could occur when running very old software
703 /// against the current Tor network,
704 /// so that the newer network is incompatible.
705 ///
706 /// It might also mean a catastrophic failure of the Tor network,
707 /// or that a deficient test network is in use.
708 ///
709 /// Currently some instances of this kind of problem
710 /// are reported as `NoPath` or `NoExit`.
711 #[display("Tor network consensus directory is not usable")]
712 TorDirectoryUnusable,
713
714 /// An operation failed because of _possible_ clock skew.
715 ///
716 /// The broken clock may be ours, or it may belong to another party on the
717 /// network. It's also possible that somebody else is lying about the time,
718 /// caching documents for far too long, or something like that.
719 #[display("possible clock skew detected")]
720 ClockSkew,
721
722 /// A directory told us that some document we were trying to upload
723 /// is not acceptable.
724 ///
725 /// This could be our fault (if we have a bug, if we're misconfigured,
726 /// if we are running very old software, etc),
727 /// or it could be the fault of the remote host
728 /// (if it is running very old software).
729 ///
730 /// In the case of an upload over unencrypted HTTP, this error
731 /// could also be the result of a MITM attacker impersonating the directory.
732 TorDocumentRejected,
733
734 /// Internal error (bug) in Arti.
735 ///
736 /// A supposedly impossible problem has arisen. This indicates a bug in
737 /// Arti; if the Arti version is relatively recent, please report the bug on
738 /// our [bug tracker](https://gitlab.torproject.org/tpo/core/arti/-/issues).
739 #[display("internal error (bug)")]
740 Internal,
741
742 /// Unclassified error
743 ///
744 /// Some other error occurred, which does not fit into any of the other kinds.
745 ///
746 /// This kind is provided for use by external code
747 /// hooking into or replacing parts of Arti.
748 /// It is never returned by the code in Arti (`arti-*` and `tor-*` crates).
749 #[display("unclassified error")]
750 Other,
751}
752
753/// Errors that can be categorized as belonging to an [`ErrorKind`]
754///
755/// The most important implementation of this trait is
756/// `arti_client::TorError`; however, other internal errors throughout Arti
757/// also implement it.
758pub trait HasKind {
759 /// Return the kind of this error.
760 fn kind(&self) -> ErrorKind;
761}
762
763#[cfg(feature = "futures")]
764impl HasKind for futures::task::SpawnError {
765 fn kind(&self) -> ErrorKind {
766 use ErrorKind as EK;
767 if self.is_shutdown() {
768 EK::ReactorShuttingDown
769 } else {
770 EK::Internal
771 }
772 }
773}
774
775impl HasKind for void::Void {
776 fn kind(&self) -> ErrorKind {
777 void::unreachable(*self)
778 }
779}
780
781impl HasKind for std::convert::Infallible {
782 fn kind(&self) -> ErrorKind {
783 unreachable!()
784 }
785}
786
787/// Sealed
788mod sealed {
789 /// Sealed
790 pub trait Sealed {}
791}