fop(1): committing to Rust error messages

This commit is contained in:
Emma Tebibyte 2024-02-23 21:46:50 -07:00
parent 448211bbe2
commit 3cee3de900
Signed by untrusted user: emma
GPG Key ID: 06FA419A1698C270

View File

@ -18,7 +18,7 @@
use std::{
env::args,
io::{ Read, stdin, Write },
io::{ Read, stdin, stdout, Write },
process::{ Command, exit, Stdio },
};
@ -54,8 +54,8 @@ fn main() {
exit(EX_USAGE);
});
let index = argv[index_arg].parse::<usize>().unwrap_or_else(|_| {
eprintln!("{}: {}: Not an integer.", argv[0], argv[1]);
let index = argv[index_arg].parse::<usize>().unwrap_or_else(|e| {
eprintln!("{}: {}: {}.", argv[0], argv[1], e);
exit(EX_DATAERR);
});
@ -74,8 +74,8 @@ fn main() {
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.unwrap_or_else( |_| {
eprintln!("{}: {}: Command not found.", argv[0], argv[command_arg]);
.unwrap_or_else( |e| {
eprintln!("{}: {}: {}.", argv[0], argv[command_arg], e);
exit(EX_UNAVAILABLE);
});
@ -83,7 +83,7 @@ fn main() {
eprintln!(
"{}: {}: No such index in input.",
argv[0],
index.to_string()
index.to_string(),
);
exit(EX_DATAERR);
});
@ -93,11 +93,8 @@ fn main() {
drop(child_stdin);
}
let output = spawned.wait_with_output().unwrap_or_else(|_| {
eprintln!("{}: {}: Command has no output.",
argv[0],
argv[command_arg]
);
let output = spawned.wait_with_output().unwrap_or_else(|e| {
eprintln!("{}: {}: {}.", argv[0], argv[command_arg], e);
exit(EX_IOERR);
});
@ -105,16 +102,17 @@ fn main() {
if replace.pop() != Some(b'\n') { replace = output.stdout; }
let new_field = String::from_utf8(replace).unwrap_or_else(|_| {
eprintln!(
"{}: {}: Command output is invalid UTF-8.",
argv[0],
argv[command_arg]
);
let new_field = String::from_utf8(replace).unwrap_or_else(|e| {
eprintln!("{}: {}: {}.", argv[0], argv[command_arg], e);
exit(EX_IOERR);
});
fields[index] = &new_field;
print!("{}", fields.join(&d.to_string()));
stdout().write_all(
fields.join(&d.to_string()).as_bytes()
).unwrap_or_else(|e|{
eprintln!("{}: {}.", argv[0], e);
exit(EX_IOERR);
});
}