From 9e018943b48405ee75744883dd2fd8f7600bc19e Mon Sep 17 00:00:00 2001 From: nokoe Date: Thu, 27 Jun 2024 13:18:19 +0200 Subject: replace unwrap with context --- server/src/data.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'server/src/data.rs') diff --git a/server/src/data.rs b/server/src/data.rs index e2944e3d..6b0442ce 100644 --- a/server/src/data.rs +++ b/server/src/data.rs @@ -19,7 +19,7 @@ use crate::{ interaction::Recipe, protocol::{DemandIndex, ItemIndex, RecipeIndex, TileIndex}, }; -use anyhow::{anyhow, bail, Result}; +use anyhow::{anyhow, bail, Context, Result}; use glam::{IVec2, Vec2}; use serde::{Deserialize, Serialize}; use std::{ @@ -142,9 +142,12 @@ impl DataIndex { let map_path = data_dir().join(format!("maps/{map}.yaml")); let recipes_path = data_dir().join(format!("recipes/{recipes}.yaml")); - let demands_in = serde_yaml::from_reader(File::open(demands_path).unwrap()).unwrap(); - let map_in = serde_yaml::from_reader(File::open(map_path).unwrap()).unwrap(); - let recipes_in = serde_yaml::from_reader(File::open(recipes_path).unwrap()).unwrap(); + let demands_in = + serde_yaml::from_reader(File::open(demands_path).context("opening demands failed")?)?; + let map_in = serde_yaml::from_reader(File::open(map_path).context("opening map failed")?)?; + let recipes_in = serde_yaml::from_reader( + File::open(recipes_path).context("opening recipes failed. are they generated yet?")?, + )?; Ok(Gamedata::build(recipes_in, map_in, demands_in)?) } -- cgit v1.2.3-70-g09d2