Unify server pinging implementations between app and backend (#5510)

* Improve ping impl to bring parity to app lib impl

* Fix issue with new impl

* fix labrinth compile

* wip: why do servers not provide server info..

* Fix ping impl overriding port

* fix theseus_gui

* remove unneeded recursion lmit
This commit is contained in:
aecsocket
2026-03-13 16:21:09 +00:00
committed by GitHub
parent 991b4d8c13
commit d14360aba5
13 changed files with 246 additions and 225 deletions

View File

@@ -1,5 +1,9 @@
//! Theseus error type
use std::sync::Arc;
use std::{
convert::Infallible,
fmt::{Debug, Display},
sync::Arc,
};
use crate::{profile, util};
use data_url::DataUrlError;
@@ -220,4 +224,41 @@ impl ErrorKind {
}
}
pub type Result<T> = core::result::Result<T, Error>;
pub type Result<T, E = Error> = core::result::Result<T, E>;
pub trait Context<T, E>: Sized {
fn wrap_err_with<D>(self, f: impl FnOnce() -> D) -> Result<T, Error>
where
D: Send + Sync + Debug + Display + 'static;
#[inline]
fn wrap_err<D>(self, msg: D) -> Result<T, Error>
where
D: Send + Sync + Debug + Display + 'static,
{
self.wrap_err_with(|| msg)
}
}
impl<T, E> Context<T, E> for Result<T, E>
where
Self: eyre::WrapErr<T, E>,
{
fn wrap_err_with<D>(self, f: impl FnOnce() -> D) -> Result<T, Error>
where
D: Send + Sync + Debug + Display + 'static,
{
eyre::WrapErr::wrap_err_with(self, f).map_err(|err| {
Error::from(ErrorKind::OtherError(format!("{err:#}")))
})
}
}
impl<T> Context<T, Infallible> for Option<T> {
fn wrap_err_with<D>(self, f: impl FnOnce() -> D) -> Result<T, Error>
where
D: Send + Sync + Debug + Display + 'static,
{
self.ok_or_else(|| Error::from(ErrorKind::OtherError(f().to_string())))
}
}