fix: avoid using terrors::OneOf across an await boundary

OneOf appears to not be Send
This commit is contained in:
Paul Campbell 2024-04-12 10:14:10 +01:00
parent 8ed942a501
commit 0b427f1d4c
3 changed files with 16 additions and 8 deletions

View file

@ -1,5 +1,4 @@
use kxio::network; use kxio::network;
use terrors::OneOf;
use tracing::{error, info, warn}; use tracing::{error, info, warn};
use crate::server; use crate::server;
@ -13,7 +12,7 @@ pub async fn get_commit_histories(
repo_details: &server::config::RepoDetails, repo_details: &server::config::RepoDetails,
config: &server::config::RepoConfig, config: &server::config::RepoConfig,
net: &kxio::network::Network, net: &kxio::network::Network,
) -> Result<CommitHistories, OneOf<(network::NetworkError,)>> { ) -> Result<CommitHistories, network::NetworkError> {
let main = (get_commit_history(repo_details, &config.branches().main(), vec![], net).await)?; let main = (get_commit_history(repo_details, &config.branches().main(), vec![], net).await)?;
let main_head = main[0].clone(); let main_head = main[0].clone();
let next = (get_commit_history( let next = (get_commit_history(
@ -47,7 +46,7 @@ async fn get_commit_history(
branch_name: &BranchName, branch_name: &BranchName,
find_commits: Vec<forge::Commit>, find_commits: Vec<forge::Commit>,
net: &kxio::network::Network, net: &kxio::network::Network,
) -> Result<Vec<forge::Commit>, OneOf<(network::NetworkError,)>> { ) -> Result<Vec<forge::Commit>, network::NetworkError> {
let hostname = &repo_details.forge.hostname; let hostname = &repo_details.forge.hostname;
let path = &repo_details.repo; let path = &repo_details.repo;
let token = &repo_details.forge.token; let token = &repo_details.forge.token;
@ -72,11 +71,7 @@ async fn get_commit_history(
None, None,
network::NetRequestLogging::None, network::NetRequestLogging::None,
); );
let result = net.get::<Vec<Commit>>(request).await; let response = net.get::<Vec<Commit>>(request).await?;
let response = result.map_err(|e| {
error!(?e, "Failed to get commit history");
OneOf::new(e)
})?;
let commits = response let commits = response
.response_body() .response_body()
.unwrap_or_default() .unwrap_or_default()

View file

@ -2,6 +2,9 @@ use std::fmt::{Display, Formatter};
pub mod forgejo; pub mod forgejo;
#[cfg(test)]
mod tests;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct CommitHistories { pub struct CommitHistories {
pub main: Vec<Commit>, pub main: Vec<Commit>,

10
src/server/forge/tests.rs Normal file
View file

@ -0,0 +1,10 @@
use kxio::network::NetworkError;
use crate::server::forge::CommitHistories;
#[test]
const fn test_is_send() {
const fn assert_send<T: Send>() {}
assert_send::<CommitHistories>();
assert_send::<NetworkError>();
}