Skip to content

Commit

Permalink
better handling of failure to auto-shard, throws a catchable exceptio…
Browse files Browse the repository at this point in the history
…n instead of leaving a dead cluster
  • Loading branch information
braindigitalis committed Sep 27, 2021
1 parent 0fcdbbf commit 623255b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/dpp/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,20 @@ error_info confirmation_callback_t::get_error() const {
void cluster::auto_shard(const confirmation_callback_t &shardinfo) {
gateway g = std::get<gateway>(shardinfo.value);
numshards = g.shards;
log(ll_info, fmt::format("Auto Shard: Bot requires {} shard{}", g.shards, g.shards > 1 ? "s" : ""));
if (g.shards) {
log(ll_info, fmt::format("Auto Shard: Bot requires {} shard{}", g.shards, (g.shards > 1) ? "s" : ""));
if (g.session_start_remaining < g.shards) {
log(ll_critical, fmt::format("Auto Shard: Discord indicates you cannot start any more sessions! Cluster startup aborted. Try again later."));
} else {
log(ll_debug, fmt::format("Auto Shard: {} of {} session starts remaining", g.session_start_remaining, g.session_start_total));
cluster::start(true);
}
} else {
log(ll_critical, "Auto Shard: Could not auto detect shard count! Cluster startup aborted.");
if (shardinfo.is_error()) {
throw dpp::exception(fmt::format("Auto Shard: Could not get shard count ({} [code: {}]). Cluster startup aborted.", shardinfo.get_error().message, shardinfo.get_error().code));
} else {
throw dpp::exception("Auto Shard: Could not get shard count (unknown error, check your connection). Cluster startup aborted.");
}
}
}

Expand Down

0 comments on commit 623255b

Please sign in to comment.