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