Skip to content

Commit a11c402

Browse files
committed
Avoid panic in stty
The expect() calls cause stty to panic if we are not attached to a tty with ENOTTY. This in turn causes shells to print messages "Aborted (core dumped)", breaking tests that assume empty stderr [with normal stderr of the process being redirected]. Simply replace .expect() with ? to handle this.
1 parent eb6bfce commit a11c402

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/uu/stty/src/stty.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ fn stty(opts: &Options) -> UResult<()> {
404404
}
405405

406406
// TODO: Figure out the right error message for when tcgetattr fails
407-
let mut termios = tcgetattr(opts.file.as_fd()).expect("Could not get terminal attributes");
407+
let mut termios = tcgetattr(opts.file.as_fd())?;
408408

409409
// iterate over valid_args, match on the arg type, do the matching apply function
410410
for arg in &valid_args {
@@ -419,12 +419,11 @@ fn stty(opts: &Options) -> UResult<()> {
419419
}
420420
}
421421
}
422-
tcsetattr(opts.file.as_fd(), set_arg, &termios)
423-
.expect("Could not write terminal attributes");
422+
tcsetattr(opts.file.as_fd(), set_arg, &termios)?;
424423
} else {
425424
// TODO: Figure out the right error message for when tcgetattr fails
426-
let termios = tcgetattr(opts.file.as_fd()).expect("Could not get terminal attributes");
427-
print_settings(&termios, opts).expect("TODO: make proper error here from nix error");
425+
let termios = tcgetattr(opts.file.as_fd())?;
426+
print_settings(&termios, opts)?;
428427
}
429428
Ok(())
430429
}

0 commit comments

Comments
 (0)