mirror of
https://github.com/uutils/awk.git
synced 2026-06-10 16:15:04 -07:00
address review: replace print macros with structured logging
Signed-off-by: SAY-5 <saiasish.cnp@gmail.com>
This commit is contained in:
@@ -93,6 +93,8 @@ unused_qualifications = "warn"
|
||||
all = { level = "warn", priority = -1 }
|
||||
cargo = { level = "warn", priority = -1 }
|
||||
pedantic = { level = "warn", priority = -1 }
|
||||
print_stdout = "warn" # restriction: forbid print/println macros
|
||||
print_stderr = "warn" # restriction: forbid eprint/eprintln macros
|
||||
use_self = "warn" # nursery lint
|
||||
cargo_common_metadata = "allow" # 3240
|
||||
multiple_crate_versions = "allow" # 2882
|
||||
|
||||
+3
-7
@@ -46,13 +46,9 @@ fn uu_main() -> Result<()> {
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
// Avoid `println!`, which panics on broken pipe / ENOSPC (e.g. `>/dev/full`).
|
||||
// Match the uutils convention: silently exit on BrokenPipe, report other I/O
|
||||
// errors to stderr and exit with failure.
|
||||
if let Err(e) = writeln!(io::stdout(), "---\n{ast}") {
|
||||
if e.kind() == io::ErrorKind::BrokenPipe {
|
||||
return Ok(());
|
||||
}
|
||||
if let Err(e) = writeln!(io::stdout(), "---\n{ast}")
|
||||
&& e.kind() != io::ErrorKind::BrokenPipe
|
||||
{
|
||||
exit_err(Some(format!("awk: error writing to standard output: {e}")));
|
||||
}
|
||||
dbg!(arena.chunk_capacity());
|
||||
|
||||
+2
-1
@@ -4,6 +4,7 @@
|
||||
// files that was distributed with this source code.
|
||||
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::io::{self, Write};
|
||||
use std::panic::{UnwindSafe, catch_unwind, set_hook, take_hook};
|
||||
use std::process::exit;
|
||||
|
||||
@@ -73,7 +74,7 @@ pub fn exit_with(res: Result<Option<impl Into<ExitCode>>, impl Display + Debug>)
|
||||
|
||||
pub fn exit_err(err: Option<impl Display + Debug>) -> ! {
|
||||
if let Some(err) = err {
|
||||
eprintln!("{err}");
|
||||
let _ = writeln!(io::stderr(), "{err}");
|
||||
}
|
||||
exit(EXIT_FAILURE)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user