Driver, Tracks: Cleanup of leaky types (#20)
Main goal: a lot of nested future/result folding. This mainly modifies error handling for Tracks and TrackHandles to be more consistent, and hides the underlying channel result passing in get_info. Errors returned should be far clearer, and are domain specific rather than falling back to a very opaque use of the underlying channel error. It should be clearer to users why their handle commands failed, or why they can't make a ytdl track loop or similar. Also fixed/cleaned up Songbird::join(_gateway) to return in a single await, sparing the user from the underlying channel details and repeated Errs. I was trying for some time to extend the same graces to `Call`, but could not figure out a sane way to get a 'static version of the first future in the chain (i.e., the gateway send) so that the whole thing could happen after dropping the lock around the Call. I really wanted to fix this to happen as a single folded await too, but I think this might need some crazy hack or redesign.
This commit is contained in:
@@ -127,10 +127,9 @@ async fn join(msg: Message, state: State) -> Result<(), Box<dyn Error + Send + S
|
||||
|
||||
let (_handle, success) = state.songbird.join(guild_id, channel_id).await;
|
||||
|
||||
let content = match success?.recv_async().await {
|
||||
Ok(Ok(())) => format!("Joined <#{}>!", channel_id),
|
||||
Ok(Err(e)) => format!("Failed to join <#{}>! Why: {:?}", channel_id, e),
|
||||
_ => format!("Failed to join <#{}>: Gateway error!", channel_id),
|
||||
let content = match success {
|
||||
Ok(()) => format!("Joined <#{}>!", channel_id),
|
||||
Err(e) => format!("Failed to join <#{}>! Why: {:?}", channel_id, e),
|
||||
};
|
||||
|
||||
state
|
||||
@@ -237,7 +236,7 @@ async fn pause(msg: Message, state: State) -> Result<(), Box<dyn Error + Send +
|
||||
let store = state.trackdata.read().await;
|
||||
|
||||
let content = if let Some(handle) = store.get(&guild_id) {
|
||||
let info = handle.get_info()?.await?;
|
||||
let info = handle.get_info().await?;
|
||||
|
||||
let paused = match info.playing {
|
||||
PlayMode::Play => {
|
||||
|
||||
Reference in New Issue
Block a user