diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-01-06 15:23:20 +0100 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-01-06 15:23:20 +0100 |
| commit | d9361edb81ee322e75851f1e4066d74ae655bf6e (patch) | |
| tree | 7a8c0778eeed7424e87675824cb13ae068a9c87f /src | |
| parent | 1d21e42ad149f0bcc9417bcf7293e3f4249cde8e (diff) | |
| download | mullvadvpn-d9361edb81ee322e75851f1e4066d74ae655bf6e.tar.xz mullvadvpn-d9361edb81ee322e75851f1e4066d74ae655bf6e.zip | |
Add monitor module error and result types
Diffstat (limited to 'src')
| -rw-r--r-- | src/process/monitor.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/process/monitor.rs b/src/process/monitor.rs index 28b2ad10de..4a19642224 100644 --- a/src/process/monitor.rs +++ b/src/process/monitor.rs @@ -84,3 +84,46 @@ impl ChildSpawner<ClonableChild> for OpenVpnBuilder { OpenVpnBuilder::spawn(self).map(|child| child.into_clonable()) } } + + +/// Type alias for results of transitions in the `ChildMonitor` state machine. +pub type TransitionResult<T> = Result<T, TransitionError>; + +/// Error type for transitions in the `ChildMonitor` state machine. +#[derive(Debug)] +pub enum TransitionError { + /// The transition could not be made because the state machine was not in a state that could + /// transition to the desired state. + InvalidState, + + /// The transition failed because of an `io::Error`. + IoError(io::Error), +} + +impl From<io::Error> for TransitionError { + fn from(error: io::Error) -> Self { + TransitionError::IoError(error) + } +} + +impl fmt::Display for TransitionError { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.write_str(self.description()) + } +} + +impl Error for TransitionError { + fn description(&self) -> &str { + match *self { + TransitionError::InvalidState => "Invalid state for desired transition", + TransitionError::IoError(..) => "Transition failed due to IO error", + } + } + + fn cause(&self) -> Option<&Error> { + match *self { + TransitionError::IoError(ref e) => Some(e), + _ => None, + } + } +} |
