Compare commits

...

3 Commits

Author SHA1 Message Date
a6b635fef0 Use separate server main in main.rs
Some checks failed
Push Workflows / rustfmt (push) Successful in 5s
Push Workflows / tailwind-build (push) Successful in 5s
Push Workflows / test (push) Successful in 18s
Push Workflows / docs (push) Successful in 19s
Push Workflows / clippy (push) Successful in 15s
Push Workflows / build (push) Successful in 42s
Push Workflows / nix-build (push) Has been cancelled
2026-06-21 16:39:41 -04:00
3c58192957 Add Result type with custom Error 2026-06-21 16:36:07 -04:00
c438e60e24 Remove redundant feature gate in server main 2026-06-21 15:44:37 -04:00
3 changed files with 23 additions and 11 deletions

View File

@@ -38,12 +38,19 @@ fn Home() -> Element {
}
}
fn main() {
fn tracing_setup() {
#[cfg(debug_assertions)]
dioxus::logger::init(tracing::Level::DEBUG).expect("Failed to initialize tracing logger");
}
#[cfg(feature = "server")]
server::main();
#[cfg(not(feature = "server"))]
fn main() {
tracing_setup();
dioxus::launch(App);
}
#[cfg(feature = "server")]
fn main() {
tracing_setup();
server::main()
}

View File

@@ -1,6 +1,9 @@
use crate::App;
pub fn main() {
#[cfg(feature = "server")]
if let Err(e) = dotenvy::dotenv() {
tracing::warn!("Error reading .env: {e}");
}
dioxus::launch(App);
}

View File

@@ -43,6 +43,8 @@ impl fmt::Display for ErrorLocation {
}
}
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Clone, Deserialize, Serialize, thiserror::Error)]
pub struct Error {
#[source]
@@ -247,9 +249,9 @@ pub trait Contextualize<R> {
fn err_context(self, context: impl Into<String>) -> R;
}
impl<T, E: Into<Error>> Contextualize<Result<T, Error>> for Result<T, E> {
impl<T, E: Into<Error>> Contextualize<Result<T>> for std::result::Result<T, E> {
#[track_caller]
fn err_context(self, context: impl Into<String>) -> Result<T, Error> {
fn err_context(self, context: impl Into<String>) -> Result<T> {
// Closures can't (currently) `track_caller`, so a simple map_err doesn't work
// See https://github.com/rust-lang/rust/issues/87417
match self {
@@ -259,16 +261,16 @@ impl<T, E: Into<Error>> Contextualize<Result<T, Error>> for Result<T, E> {
}
}
impl<T> Contextualize<Result<T, Error>> for Option<T> {
impl<T> Contextualize<Result<T>> for Option<T> {
#[track_caller]
fn err_context(self, context: impl Into<String>) -> Result<T, Error> {
fn err_context(self, context: impl Into<String>) -> Result<T> {
self.ok_or(Error::new_here(ErrorType::Error(context.into())))
}
}
impl<T, E: Into<Error>> Contextualize<Result<T, Error>> for E {
impl<T, E: Into<Error>> Contextualize<Result<T>> for E {
#[track_caller]
fn err_context(self, context: impl Into<String>) -> Result<T, Error> {
fn err_context(self, context: impl Into<String>) -> Result<T> {
Err(self.into().with_context(context))
}
}