diff --git a/components/common/src/error.rs b/components/common/src/error.rs index 8ee7a51619d..3cc3408ab83 100644 --- a/components/common/src/error.rs +++ b/components/common/src/error.rs @@ -49,6 +49,7 @@ pub enum Error { GossipFileRelativePath(String), HabitatCore(hcore::Error), InstallHookFailed(PackageIdent), + InvalidEventStreamToken(String), InvalidInstallHookMode(String), /// Occurs when making lower level IO calls. IO(io::Error), @@ -121,6 +122,9 @@ impl fmt::Display for Error { Error::InstallHookFailed(ref ident) => { format!("Install hook exited unsuccessfully: {}", ident) } + Error::InvalidEventStreamToken(ref s) => { + format!("Invalid event stream token provided: '{}'", s) + } Error::InvalidInstallHookMode(ref e) => { format!("Invalid InstallHookMode conversion from {}", e) } @@ -185,6 +189,7 @@ impl error::Error for Error { } Error::HabitatCore(ref err) => err.description(), Error::InstallHookFailed(_) => "Install hook exited unsuccessfully", + Error::InvalidEventStreamToken(_) => "Invalid event stream token provided", Error::InvalidInstallHookMode(_) => "Invalid InstallHookMode", Error::IO(ref err) => err.description(), Error::JoinPathsError(ref err) => err.description(), diff --git a/components/common/src/types/mod.rs b/components/common/src/types/mod.rs index 43aff274f3d..132c2bf1ddf 100644 --- a/components/common/src/types/mod.rs +++ b/components/common/src/types/mod.rs @@ -128,13 +128,31 @@ impl AutomateAuthToken { } impl FromStr for AutomateAuthToken { - type Err = (); + type Err = Error; fn from_str(s: &str) -> std::result::Result { - Ok(AutomateAuthToken(s.to_string())) + if s.is_empty() { + Err(Error::InvalidEventStreamToken(s.to_string())) + } else { + Ok(AutomateAuthToken(s.to_string())) + } } } impl fmt::Display for AutomateAuthToken { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.0) } } + +#[cfg(test)] +mod test { + use super::*; + + mod auth_token { + use super::*; + + #[test] + fn cannot_parse_from_empty_string() { assert!("".parse::().is_err()) } + + } + +}