1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//! Public error type for `rusty-autossh`.
//!
//! Defines the [`AutosshError`] enum returned from the library API
//! ([`crate::SshSupervisor::run`], [`crate::SshSupervisorBuilder::build`]) and
//! used internally by all crate modules.
//!
//! # Forward-compatibility (SemVer policy)
//!
//! [`AutosshError`] is `#[non_exhaustive]` per AD-014, so additive variants in
//! later releases are NOT a breaking change. Downstream consumers MUST include
//! a wildcard `_` arm when pattern-matching:
//!
//! ```
//! # use rusty_autossh::AutosshError;
//! # fn handle(e: AutosshError) {
//! match e {
//! AutosshError::SshNotFound { .. } => { /* ... */ }
//! AutosshError::Io(_) => { /* ... */ }
//! _ => { /* required wildcard arm */ }
//! }
//! # }
//! ```
//!
//! Exhaustive matches on `#[non_exhaustive]` types from a different crate are
//! a compile error — this guards downstream consumers from breakage when new
//! variants are added in later releases:
//!
//! ```compile_fail
//! use rusty_autossh::AutosshError;
//!
//! fn handle(e: AutosshError) {
//! // Missing the required wildcard `_` arm — fails to compile because
//! // `AutosshError` is `#[non_exhaustive]`.
//! match e {
//! AutosshError::SshNotFound { .. } => {}
//! AutosshError::MonitorBindFailed { .. } => {}
//! AutosshError::MaxStartReached { .. } => {}
//! AutosshError::MaxLifetimeReached => {}
//! AutosshError::PidfileWrite { .. } => {}
//! AutosshError::LogfileWrite { .. } => {}
//! AutosshError::Io(_) => {}
//! AutosshError::Daemonize { .. } => {}
//! AutosshError::Internal(_) => {}
//! }
//! }
//! ```
use io;
use PathBuf;
/// Errors returned by the `rusty-autossh` library API.
///
/// `Send + Sync + 'static` per SC-009. `#[non_exhaustive]` per AD-014 so
/// additive variants are not a breaking change.
///
/// `source()` returns the wrapped inner error for wrapping variants (those
/// holding a `source: io::Error` field, the `#[from]` `Io` variant) and
/// `None` for leaf variants (no inner source).
///
/// # Example
///
/// ```
/// use std::io;
/// use rusty_autossh::AutosshError;
///
/// // io::Error converts via `#[from]` (AD-014).
/// let io_err = io::Error::new(io::ErrorKind::NotFound, "boom");
/// let err: AutosshError = io_err.into();
/// match err {
/// AutosshError::Io(_) => {}
/// _ => unreachable!(),
/// }
/// ```