Better error handling

This commit is contained in:
2026-05-24 07:36:43 +01:00
parent 74aa9e8a84
commit 08c028bfa8
6 changed files with 55 additions and 20 deletions
+37 -8
View File
@@ -1,14 +1,11 @@
use crate::{gtfs, renderer};
use std::collections::HashSet;
extern crate serde_derive;
extern crate serde_yaml;
use serde::{Serialize, Deserialize};
use std::fs;
use yaml_serde;
struct Error {
message: String
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct Config {
pub struct Config {
#[serde(rename = "gtfs")]
pub gtfs_prefs: gtfs::structs::Preferences,
@@ -16,7 +13,39 @@ struct Config {
pub screen_prefs: renderer::structs::Prefs,
}
#[derive (Debug)]
pub struct Error {
pub message: String
}
impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self {
return Error {
message: value.to_string(),
};
}
}
impl From<yaml_serde::Error> for Error {
fn from(value: yaml_serde::Error) -> Self {
return Error {
message: value.to_string(),
}
}
}
impl From<sdl3::Error> for Error {
fn from(value: sdl3::Error) -> Self {
return Error {
message: value.to_string(),
}
}
}
pub fn load_config(config_name: String) -> Result<Config, Error> {
return Err(Error { message: String::from("Foo") });
let config_text = fs::read_to_string(config_name)?;
let config = yaml_serde::from_str(config_text.as_ref())?;
return Ok(config);
}