Skip to content

Commit

Permalink
Remove all instances of unwrap() from config
Browse files Browse the repository at this point in the history
Unwrapping inside the config file parsing can lead to some issues that
prevent us from falling back to a default configuration file.

One instance of that issue was mentioned in alacritty#1135.

Now all instances of `unwrap()` have been removed and replaced with
proper error handling. This will make the config more robust and
prevents live reload from silently breaking while alacritty is running.

This also fixes a few currently existing clippy issues.
Clippy added an additonal lint which complains about `MyStruct { field:
field }`.

These issues have been fixed, except for some false-positives and issues
in external macros which will probably be fixed with future updates (bitflags/bitflags#149)
  • Loading branch information
chrisduerr committed Mar 4, 2018
1 parent 85d0160 commit 5f9f927
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 124 deletions.
34 changes: 17 additions & 17 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions src/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn parse_rgb_color(color: &[u8]) -> Option<Rgb> {
if next!() != Some('/') { return None; }
let b = parse_hex!();

Some(Rgb { r: r, g: g, b: b})
Some(Rgb { r, g, b })
}
Some('#') => {
Some(Rgb {
Expand Down Expand Up @@ -128,8 +128,8 @@ impl<'a, H: Handler + TermInfo + 'a, W: io::Write> Performer<'a, H, W> {
) -> Performer<'b, H, W> {
Performer {
_state: state,
handler: handler,
writer: writer,
handler,
writer,
}
}
}
Expand Down
47 changes: 21 additions & 26 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl<'a> Shell<'a> {
{
Shell {
program: program.into(),
args: args
args,
}
}

Expand Down Expand Up @@ -678,9 +678,9 @@ struct RawBinding {

impl RawBinding {
fn into_mouse_binding(self) -> ::std::result::Result<MouseBinding, Self> {
if self.mouse.is_some() {
if let Some(mouse) = self.mouse {
Ok(Binding {
trigger: self.mouse.unwrap(),
trigger: mouse,
mods: self.mods,
action: self.action,
mode: self.mode,
Expand All @@ -692,9 +692,9 @@ impl RawBinding {
}

fn into_key_binding(self) -> ::std::result::Result<KeyBinding, Self> {
if self.key.is_some() {
if let Some(key) = self.key {
Ok(KeyBinding {
trigger: self.key.unwrap(),
trigger: key,
mods: self.mods,
action: self.action,
mode: self.mode,
Expand Down Expand Up @@ -865,12 +865,12 @@ impl<'a> de::Deserialize<'a> for RawBinding {
}

Ok(RawBinding {
mode: mode,
mode,
notmode: not_mode,
action: action,
key: key,
mouse: mouse,
mods: mods,
action,
key,
mouse,
mods,
})
}
}
Expand Down Expand Up @@ -977,8 +977,8 @@ impl CursorOrPrimaryColors {
fn into_cursor_colors(self) -> CursorColors {
match self {
CursorOrPrimaryColors::Cursor { text, cursor } => CursorColors {
text: text,
cursor: cursor
text,
cursor,
},
CursorOrPrimaryColors::Primary { foreground, background } => {
// Must print in config since logger isn't setup yet.
Expand Down Expand Up @@ -1124,22 +1124,22 @@ impl FromStr for Rgb {
macro_rules! component {
($($c:ident),*) => {
$(
match chars.next().unwrap().to_digit(16) {
match chars.next().and_then(|c| c.to_digit(16)) {
Some(val) => rgb.$c = (val as u8) << 4,
None => return Err(())
}

match chars.next().unwrap().to_digit(16) {
match chars.next().and_then(|c| c.to_digit(16)) {
Some(val) => rgb.$c |= val as u8,
None => return Err(())
}
)*
}
}

match chars.next().unwrap() {
'0' => if chars.next().unwrap() != 'x' { return Err(()); },
'#' => (),
match chars.next() {
Some('0') => if chars.next() != Some('x') { return Err(()); },
Some('#') => (),
_ => return Err(()),
}

Expand Down Expand Up @@ -1429,8 +1429,8 @@ impl Default for Dimensions {
impl Dimensions {
pub fn new(columns: Column, lines: Line) -> Self {
Dimensions {
columns: columns,
lines: lines
columns,
lines,
}
}

Expand Down Expand Up @@ -1668,7 +1668,8 @@ impl Monitor {
_thread: ::util::thread::spawn_named("config watcher", move || {
let (tx, rx) = mpsc::channel();
// The Duration argument is a debouncing period.
let mut watcher = watcher(tx, Duration::from_millis(10)).unwrap();
let mut watcher = watcher(tx, Duration::from_millis(10))
.expect("Unable to spawn file watcher");
let config_path = ::std::fs::canonicalize(path)
.expect("canonicalize config path");

Expand Down Expand Up @@ -1742,7 +1743,6 @@ enum Key {
Key8,
Key9,
Key0,

A,
B,
C,
Expand All @@ -1769,9 +1769,7 @@ enum Key {
X,
Y,
Z,

Escape,

F1,
F2,
F3,
Expand All @@ -1787,7 +1785,6 @@ enum Key {
F13,
F14,
F15,

Snapshot,
Scroll,
Pause,
Expand All @@ -1797,7 +1794,6 @@ enum Key {
End,
PageDown,
PageUp,

Left,
Up,
Right,
Expand All @@ -1817,7 +1813,6 @@ enum Key {
Numpad7,
Numpad8,
Numpad9,

AbntC1,
AbntC2,
Add,
Expand Down
14 changes: 7 additions & 7 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,15 @@ impl Display {
});

Ok(Display {
window: window,
renderer: renderer,
glyph_cache: glyph_cache,
render_timer: render_timer,
tx: tx,
rx: rx,
window,
renderer,
glyph_cache,
render_timer,
tx,
rx,
meter: Meter::new(),
font_size: font::Size::new(0.),
size_info: size_info,
size_info,
last_background_color: background_color,
})
}
Expand Down
8 changes: 4 additions & 4 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ impl<N: Notify> Processor<N> {
mouse_config: config.mouse().to_owned(),
print_events: options.print_events,
wait_for_event: true,
notifier: notifier,
resize_tx: resize_tx,
ref_test: ref_test,
notifier,
resize_tx,
ref_test,
mouse: Default::default(),
selection: None,
size_info: size_info,
size_info,
hide_cursor_when_typing: config.hide_cursor_when_typing(),
hide_cursor: false,
received_count: 0,
Expand Down
12 changes: 6 additions & 6 deletions src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ impl<Io> EventLoop<Io>
let (tx, rx) = channel::channel();
EventLoop {
poll: mio::Poll::new().expect("create mio Poll"),
pty: pty,
tx: tx,
rx: rx,
terminal: terminal,
display: display,
ref_test: ref_test,
pty,
tx,
rx,
terminal,
display,
ref_test,
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ impl<T: Clone> Grid<T> {
}

Grid {
raw: raw,
cols: cols,
lines: lines,
raw,
cols,
lines,
}
}

Expand Down
Loading

0 comments on commit 5f9f927

Please sign in to comment.