Skip to main content

Crate deno_print

Crate deno_print 

Source
Expand description

Replacements for the std print!, println!, eprint! and eprintln! macros that drop write errors instead of panicking, named after Cargo’s macros with the same semantics.

The Rust runtime ignores SIGPIPE, so when the other end of a pipe is closed (ex. deno test | head) writes to stdout surface as EPIPE errors, which make the std print macros panic. The macros in this crate drop write errors instead, matching how Node.js treats EPIPE on stdout and how env_logger treats write errors.

use deno_print::drop_println;

drop_println!("hello there");

Use these macros for output that is the program’s deliverable and must go to stdout (ex. subcommand reporters). For diagnostic output prefer the log crate, which is also tolerant to write errors and integrates with the progress bar and telemetry.

See https://github.com/denoland/deno/issues/15767

Macros§

drop_eprint
Like std::eprint!, but drops write errors instead of panicking.
drop_eprintln
Like std::eprintln!, but drops write errors instead of panicking.
drop_print
Like std::print!, but drops write errors instead of panicking.
drop_println
Like std::println!, but drops write errors instead of panicking.

Functions§

drop_write_stdout
Writes pre-encoded bytes to stdout, dropping write errors instead of surfacing them. The byte-slice sibling of drop_print! for output that is not produced via format args (ex. serialized JSON, bundle contents).