Better error handling

This commit is contained in:
Alex Bethel 2022-03-03 12:08:08 -07:00
parent 677c101505
commit 257f43f02a
2 changed files with 12 additions and 12 deletions

View file

@ -10,7 +10,7 @@ use thiserror::Error;
/// Initializes the terminal to accept user input, and creates a new /// Initializes the terminal to accept user input, and creates a new
/// Window. /// Window.
pub fn init_window() -> Window { pub fn init_window() -> Result<Window, ColorError> {
// Create a new window over the terminal. // Create a new window over the terminal.
let window = initscr(); let window = initscr();
@ -22,16 +22,10 @@ pub fn init_window() -> Window {
// upper-left corner of the screen when they type a character. // upper-left corner of the screen when they type a character.
noecho(); noecho();
// // Set up a color palette. TODO // Set up a color palette.
// init_colors().unwrap(); init_colors()?;
let c = init_colors();
if let Err(e) = c {
endwin();
println!("{}", e);
panic!();
}
window Ok(window)
} }
/// Cleans everything up and exits the game. /// Cleans everything up and exits the game.
@ -55,7 +49,7 @@ pub enum Color {
} }
#[derive(Error, Debug)] #[derive(Error, Debug)]
enum ColorError { pub enum ColorError {
#[error("colors not supported")] #[error("colors not supported")]
NoColors, NoColors,

View file

@ -48,7 +48,13 @@ fn main() {
.with(MobSystem, "mobs", &[]) .with(MobSystem, "mobs", &[])
.build(); .build();
let mut window = init_window(); let mut window = match init_window() {
Ok(window) => window,
Err(err) => {
println!("Error initializing window: {}", err);
return;
},
};
loop { loop {
dispatcher.dispatch(&world); dispatcher.dispatch(&world);