aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2018-09-25 18:43:06 +0200
committerTeddy Wing2018-09-25 18:43:06 +0200
commit0ec3b951795b04359ddc99ef9199a45a9b60bf03 (patch)
tree9b9f298a94480f85b9b301841cca362ba57fd659 /src
parent43cb01b377d5fcb01acd7a2972cca2b428eeef33 (diff)
downloaddome-key-map-0ec3b951795b04359ddc99ef9199a45a9b60bf03.tar.bz2
state_load_map_group(): Log errors instead of panicking
This allows us to log the errors without exiting the program.
Diffstat (limited to 'src')
-rw-r--r--src/cocoa_bridge.rs57
-rw-r--r--src/lib.rs3
2 files changed, 37 insertions, 23 deletions
diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs
index 0eb603a..5c7c40d 100644
--- a/src/cocoa_bridge.rs
+++ b/src/cocoa_bridge.rs
@@ -114,29 +114,40 @@ pub extern "C" fn state_free(ptr: *mut State) {
#[no_mangle]
pub extern "C" fn state_load_map_group(ptr: *mut State) {
- let xdg_dirs = xdg::BaseDirectories::with_prefix("dome-key").unwrap();
- let mapping_file = xdg_dirs.find_config_file("mappings.dkmap")
- .expect(
- &format!(
- "No mapping file found at '{}{}'",
- xdg_dirs.get_config_home()
- .to_str()
- .expect("Config home path contains invalid unicode"),
- "mappings.dkmap"
- )
- );
-
- let state = unsafe {
- assert!(!ptr.is_null());
- &mut *ptr
- };
-
- let dkmap = fs::read_to_string(mapping_file)
- .expect("Failed to read 'mappings.dkmap'");
- state.map_group = Some(
- MapGroup::parse(&dkmap)
- .expect("Failed to parse 'mappings.dkmap'")
- );
+ match xdg::BaseDirectories::with_prefix("dome-key") {
+ Ok(xdg_dirs) => {
+ match xdg_dirs.find_config_file("mappings.dkmap") {
+ Some(mapping_file) => {
+ let state = unsafe {
+ assert!(!ptr.is_null());
+ &mut *ptr
+ };
+
+ let dkmap = fs::read_to_string(mapping_file)
+ .expect("Failed to read 'mappings.dkmap'");
+ state.map_group = Some(
+ MapGroup::parse(&dkmap)
+ .expect("Failed to parse 'mappings.dkmap'")
+ );
+ },
+ None => {
+ match xdg_dirs.get_config_home().to_str() {
+ Some(config_home) => {
+ error!(
+ "No mapping file found at '{}{}'",
+ config_home,
+ "mappings.dkmap"
+ )
+ },
+ None => {
+ error!("Config home path contains invalid unicode")
+ }
+ }
+ },
+ }
+ },
+ Err(e) => error!("{}", e),
+ }
}
#[no_mangle]
diff --git a/src/lib.rs b/src/lib.rs
index 16be4e0..13d70e8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -4,6 +4,9 @@ extern crate autopilot;
#[macro_use]
extern crate combine;
extern crate libc;
+
+#[macro_use]
+extern crate log;
extern crate xdg;
mod cocoa_bridge;