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.
This commit is contained in:
Julian Andres Klode 2025-09-05 13:50:31 +02:00
parent eb6bfce7a9
commit a11c4022eb

View file

@ -404,7 +404,7 @@ fn stty(opts: &Options) -> UResult<()> {
}
// TODO: Figure out the right error message for when tcgetattr fails
let mut termios = tcgetattr(opts.file.as_fd()).expect("Could not get terminal attributes");
let mut termios = tcgetattr(opts.file.as_fd())?;
// iterate over valid_args, match on the arg type, do the matching apply function
for arg in &valid_args {
@ -419,12 +419,11 @@ fn stty(opts: &Options) -> UResult<()> {
}
}
}
tcsetattr(opts.file.as_fd(), set_arg, &termios)
.expect("Could not write terminal attributes");
tcsetattr(opts.file.as_fd(), set_arg, &termios)?;
} else {
// TODO: Figure out the right error message for when tcgetattr fails
let termios = tcgetattr(opts.file.as_fd()).expect("Could not get terminal attributes");
print_settings(&termios, opts).expect("TODO: make proper error here from nix error");
let termios = tcgetattr(opts.file.as_fd())?;
print_settings(&termios, opts)?;
}
Ok(())
}