aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-06-06 20:10:25 -0700
committerZeyla Hellyer <[email protected]>2017-06-06 20:10:25 -0700
commit858bbf298d08ada3ae6c5b24105bf751bc938d5e (patch)
treeb9be86c16c1bc8e7cb130a03ac31ec0ec56193a8 /src
parentMake client join shards and return (diff)
downloadserenity-858bbf298d08ada3ae6c5b24105bf751bc938d5e.tar.xz
serenity-858bbf298d08ada3ae6c5b24105bf751bc938d5e.zip
Make client starts return an error
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.
Diffstat (limited to 'src')
-rw-r--r--src/client/error.rs4
-rw-r--r--src/client/mod.rs37
2 files changed, 39 insertions, 2 deletions
diff --git a/src/client/error.rs b/src/client/error.rs
index a08d15b..1a23599 100644
--- a/src/client/error.rs
+++ b/src/client/error.rs
@@ -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 {
@@ -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",
}
}
}
diff --git a/src/client/mod.rs b/src/client/mod.rs
index ff5e4bd..f728792 100644
--- a/src/client/mod.rs
+++ b/src/client/mod.rs
@@ -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()?;
@@ -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
@@ -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
@@ -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
@@ -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.
@@ -1012,7 +1045,7 @@ impl Client {
let _ = thread.join();
}
- Ok(())
+ Err(Error::Client(ClientError::Shutdown))
}
}