style: put the error checks next to each other

main
Angelo Fallaria 2 years ago
parent 067cbe2843
commit 920458cdf7

@ -118,16 +118,12 @@ fn parse_contents(contents: String) -> Result<Vec<Hotkey>, Error> {
let mut keysyms: Vec<evdev::Key> = Vec::new();
if key_to_evdev_key.contains_key(lines[i].trim()) {
// If the keybind line is at the very last line,
// it's impossible for there to be a command
// Error if keybind line is at the very last line
// ( It's impossible for there to be a command )
if i >= lines.len() - 1 {
return Err(Error::InvalidConfig(ParseError::MissingCommand(real_line_no)));
}
// Translate keypress into evdev key
let keysym = key_to_evdev_key.get(lines[i].trim()).unwrap();
keysyms.push(*keysym);
// Error if empty command
if lines[i + 1].trim().is_empty() {
return Err(Error::InvalidConfig(ParseError::MissingCommand(real_line_no + 1)));
@ -140,6 +136,10 @@ fn parse_contents(contents: String) -> Result<Vec<Hotkey>, Error> {
)));
}
// Translate keypress into evdev key
let keysym = key_to_evdev_key.get(lines[i].trim()).unwrap();
keysyms.push(*keysym);
// Parse the command, also handling multiline commands
let mut command = String::new();
let mut j = i + 1;

Loading…
Cancel
Save