Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unwrap .spawn() to support updated tokio task builder API #2349

Merged
merged 2 commits into from Mar 8, 2023

Conversation

zackradisic
Copy link
Contributor

When compiling serenity with the tokio_task_builder feature enabled, the following error occurs:

error[E0308]: mismatched types
 --> /Users/zackradisic/.cargo/registry/src/github.com-1ecc6299db9ec823/serenity-0.11.5/src/internal/tokio.rs:9:5
  |
4 | pub fn spawn_named<F, T>(name: &str, future: F) -> tokio::task::JoinHandle<T>
  |                                                    -------------------------- expected `tokio::task::JoinHandle<T>` because of return type
...
9 |     tokio::task::Builder::new().name(&*format!("serenity::{}", name)).spawn(future)
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `tokio::task::JoinHandle`, found enum `std::result::Result`
  |
  = note: expected struct `tokio::task::JoinHandle<_>`
               found enum `std::result::Result<tokio::task::JoinHandle<_>, std::io::Error>`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `serenity` due to previous error

In this commit tokio's task::Builder::spawn* methods were changed to return an std::io::Result<_> to allowing opt-in to gracefully handling errors when spawning tasks (PR). According to git it has been present since tokio version 1.21.0

The PR says the previous behaviour was to simply panic on failure, so a simple fix is to do the same and .unwrap() the value returned from spawning

@mkrasnitski
Copy link
Collaborator

This is alright to do on current (since the build is otherwise broken), but on next it might be better to change the function signature to return a Result<JoinHandle<T>>.

src/internal/tokio.rs Outdated Show resolved Hide resolved
@arqunis arqunis added the fix A solution to an existing bug. label Mar 8, 2023
@arqunis arqunis merged commit f42ec02 into serenity-rs:current Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix A solution to an existing bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants