From 7ce3bb857755a82c2a4904a85f37697c634d4e67 Mon Sep 17 00:00:00 2001 From: Serkyo Date: Wed, 8 Jul 2026 15:14:45 +0200 Subject: [PATCH] refactor(server): propagate config-load errors via anyhow --- Cargo.lock | 5 +++-- Cargo.toml | 1 + crates/client/Cargo.toml | 2 +- crates/server/Cargo.toml | 1 + crates/server/src/main.rs | 11 ++++++----- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3b45ba8..d7734df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,9 +67,9 @@ checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04" [[package]] name = "anyhow" -version = "1.0.102" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" +checksum = "2a4385e2e34eb35d6b3efe798b9eb88096925d87726c0798709bf56d9ed84af3" [[package]] name = "arrayref" @@ -1776,6 +1776,7 @@ dependencies = [ name = "server" version = "0.1.0" dependencies = [ + "anyhow", "bevy_ecs", "crossbeam-channel", "glam 0.33.2", diff --git a/Cargo.toml b/Cargo.toml index 024f630..506e4e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ version = "0.1.0" # Dependencies used by more than one crate are pinned once here so a version can never drift between crates. [workspace.dependencies] +anyhow = "1.0.103" glam = { version = "0.33", features = ["serde"] } bytemuck = { version = "1.21", features = ["derive"] } tracing = "0.1.44" diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.toml index cbfaa00..e9e9353 100644 --- a/crates/client/Cargo.toml +++ b/crates/client/Cargo.toml @@ -9,7 +9,7 @@ authors.workspace = true workspace = true [dependencies] -anyhow = "1.0.102" +anyhow = { workspace = true } tracing = { workspace = true } tracing-subscriber = { workspace = true } winit = "0.30.13" diff --git a/crates/server/Cargo.toml b/crates/server/Cargo.toml index 1002923..e76c546 100644 --- a/crates/server/Cargo.toml +++ b/crates/server/Cargo.toml @@ -9,6 +9,7 @@ authors.workspace = true workspace = true [dependencies] +anyhow = { workspace = true } bevy_ecs = "0.19" crossbeam-channel = "0.5.16" glam = { workspace = true } diff --git a/crates/server/src/main.rs b/crates/server/src/main.rs index 710db45..5752e95 100644 --- a/crates/server/src/main.rs +++ b/crates/server/src/main.rs @@ -13,6 +13,7 @@ pub mod world_server; use std::collections::HashSet; use std::fs; +use anyhow::Context; use bevy_ecs::prelude::{Query, ResMut, Schedule, With, World}; use glam::Vec3; use shared::generator::{VoxelGenerator, WorldGenConfig}; @@ -43,7 +44,7 @@ fn stream_chunks( ); } -fn main() { +fn main() -> anyhow::Result<()> { tracing_subscriber::fmt() .with_env_filter( tracing_subscriber::EnvFilter::try_from_default_env() @@ -53,13 +54,11 @@ fn main() { info!("Starting Synvael server"); - #[expect(clippy::expect_used)] let config_str = fs::read_to_string("assets/data/worldgen/default.json") - .expect("Failed to read worldgen config"); + .context("reading worldgen config assets/data/worldgen/default.json")?; - #[expect(clippy::expect_used)] let worldgen_config: WorldGenConfig = - serde_json::from_str(&config_str).expect("Failed to parse worldgen config"); + serde_json::from_str(&config_str).context("parsing worldgen config as JSON")?; info!("Successfully loaded world configuration"); debug!("Base height: {}", worldgen_config.base_height); @@ -115,4 +114,6 @@ fn main() { position.0.chunk.x += 1; } } + + Ok(()) }