Skip to content

Commit

Permalink
Make client starts return an error
Browse files Browse the repository at this point in the history
When returning, the Client would return an Ok(()). Instead, return an
error, since there is currently no reason the client would return under
"okay" circumstances.
  • Loading branch information
Zeyla Hellyer committed Jun 7, 2017
1 parent 175d3a3 commit 858bbf2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/client/error.rs
Expand Up @@ -21,6 +21,9 @@ pub enum Error {
/// When a shard has completely failed to reboot after resume and/or
/// reconnect attempts.
ShardBootFailure,
/// When all shards that the client is responsible for have shutdown with an
/// error.
Shutdown,
}

impl Display for Error {
Expand All @@ -34,6 +37,7 @@ impl StdError for Error {
match *self {
Error::InvalidToken => "The provided token was invalid",
Error::ShardBootFailure => "Failed to (re-)boot a shard",
Error::Shutdown => "The clients shards shutdown",
}
}
}
37 changes: 35 additions & 2 deletions src/client/mod.rs
Expand Up @@ -347,6 +347,12 @@ impl Client {
/// # }
/// ```
///
/// # Errors
///
/// Returns a [`ClientError::Shutdown`] when all shards have shutdown due to
/// an error.
///
/// [`ClientError::Shutdown`]: enum.ClientError.html#variant.Shutdown
/// [gateway docs]: gateway/index.html#sharding
pub fn start_autosharded(&mut self) -> Result<()> {
let mut res = http::get_bot_gateway()?;
Expand Down Expand Up @@ -419,6 +425,12 @@ impl Client {
/// # }
/// ```
///
/// # Errors
///
/// Returns a [`ClientError::Shutdown`] when all shards have shutdown due to
/// an error.
///
/// [`ClientError::Shutdown`]: enum.ClientError.html#variant.Shutdown
/// [`start`]: #method.start
/// [`start_autosharded`]: #method.start_autosharded
/// [gateway docs]: gateway/index.html#sharding
Expand Down Expand Up @@ -462,6 +474,12 @@ impl Client {
/// # }
/// ```
///
/// # Errors
///
/// Returns a [`ClientError::Shutdown`] when all shards have shutdown due to
/// an error.
///
/// [`ClientError::Shutdown`]: enum.ClientError.html#variant.Shutdown
/// [`start_shard`]: #method.start_shard
/// [`start_shard_range`]: #method.start_shard_range
/// [Gateway docs]: gateway/index.html#sharding
Expand Down Expand Up @@ -516,6 +534,13 @@ impl Client {
/// # }
/// ```
///
/// # Errors
///
/// Returns a [`ClientError::Shutdown`] when all shards have shutdown due to
/// an error.
///
///
/// [`ClientError::Shutdown`]: enum.ClientError.html#variant.Shutdown
/// [`start_shard`]: #method.start_shard
/// [`start_shards`]: #method.start_shards
/// [Gateway docs]: gateway/index.html#sharding
Expand Down Expand Up @@ -919,7 +944,15 @@ impl Client {
// 2: total number of shards the bot is sharding for
//
// Not all shards need to be initialized in this process.
fn start_connection(&mut self, shard_data: Option<[u64; 3]>, url: String) -> Result<()> {
//
// # Errors
//
// Returns a [`ClientError::Shutdown`] when all shards have shutdown due to
// an error.
//
// [`ClientError::Shutdown`]: enum.ClientError.html#variant.Shutdown
fn start_connection(&mut self, shard_data: Option<[u64; 3]>, url: String)
-> Result<()> {
// Update the framework's current user if the feature is enabled.
//
// This also acts as a form of check to ensure the token is correct.
Expand Down Expand Up @@ -1012,7 +1045,7 @@ impl Client {
let _ = thread.join();
}

Ok(())
Err(Error::Client(ClientError::Shutdown))
}
}

Expand Down

0 comments on commit 858bbf2

Please sign in to comment.