fix: gracefully exit when misconfigured or unavailable audio backend

When the user has an error in their audio backend configuration or
doesn't have audio backends available, gracefully exit instead of
panicking.
This commit is contained in:
Thomas Frans
2024-02-04 23:22:32 +01:00
committed by Henrik Friedrichsen
parent 15515c27b5
commit 38010b4c76
4 changed files with 68 additions and 33 deletions

View File

@@ -3,10 +3,11 @@ extern crate cursive;
#[macro_use]
extern crate serde;
use std::path::PathBuf;
use std::{path::PathBuf, process::exit};
use application::{setup_logging, Application};
use config::set_configuration_base_path;
use log::error;
use ncspot::program_arguments;
mod application;
@@ -60,10 +61,20 @@ fn main() -> Result<(), String> {
Some((_, _)) => unreachable!(),
None => {
// Create the application.
let mut application = Application::new(matches.get_one::<String>("config").cloned())?;
let mut application =
match Application::new(matches.get_one::<String>("config").cloned()) {
Ok(application) => application,
Err(error) => {
eprintln!("{error}");
error!("{error}");
exit(-1);
}
};
// Start the application event loop.
application.run()
}
}
}?;
Ok(())
}