Skip to content

Commit

Permalink
Introduce some logging
Browse files Browse the repository at this point in the history
Currently, only flag invalid config file and missing icon.

Remove the catch-all fallback for a missing icon in the default config.

This should make it easy for the user to troubleshoot missing icons.

Since the config is live-reloaded, it should all be a pretty smooth
experience.
  • Loading branch information
pierrechevalier83 committed Sep 18, 2019
1 parent 79d0c16 commit 41affcc
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 7 deletions.
159 changes: 159 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ i3ipc = "0.10.1"
dirs = "2.0.2"
serde_yaml = "0.8.9"
structopt = "0.3.1"
pretty_env_logger = "0.3.1"
log = "0.4.8"
5 changes: 3 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Proper error handling
Also, log things properly with a logger.
More logging
Decide if I want to pursue something more robust than the app name using the app id
README
publish crate
10 changes: 7 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ fn get_icon_mappings_from_config(config: &PathBuf) -> Result<Vec<(String, String
let mut config_file = File::open(config)?;
let mut content = String::new();
config_file.read_to_string(&mut content)?;
// TODO: log that error
serde_yaml::from_str(&content)
.map_err(|_| Error::new(ErrorKind::Other, "Invalid configuration file"))
serde_yaml::from_str(&content).map_err(|_| {
log::error!(
"Error parsing configuration file.\nInvalid syntax in {:#?}.",
config
);
Error::new(ErrorKind::Other, "Invalid configuration file")
})
}

fn get_icon_mappings_from_default_config() -> Vec<(String, String)> {
Expand Down
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ fn pretty_window(window: &String, icon_mappings: &[(String, String)]) -> String
return icon.clone();
}
}
println!("Couldn't identify window: {}", window);
"".into()
log::error!("Couldn't identify window: {}", window);
log::info!("Make sure to add an icon for this file in your config file!");
" ".into()
}

fn pretty_windows(windows: &Vec<Option<String>>, icon_mappings: &[(String, String)]) -> String {
Expand All @@ -96,6 +97,7 @@ fn pretty_windows(windows: &Vec<Option<String>>, icon_mappings: &[(String, Strin
}

fn main() {
pretty_env_logger::init();
let _ = Options::from_args();
let mut wm = I3Connection::connect().unwrap();
let mut listener = I3EventListener::connect().unwrap();
Expand Down

0 comments on commit 41affcc

Please sign in to comment.