oxidecomputer / oxide.rs

The Oxide Rust SDK and CLI
Mozilla Public License 2.0
37 stars 12 forks source link

Ignore EPIPE in CLI #746

Closed wfchandler closed 1 month ago

wfchandler commented 1 month ago

Piping command output to a process that performs a partial read before closing the pipe, such as head, will cause an EPIPE to be raised on the next write attempt. The standard (e)print(ln)! macros will panic on any errors when writing, including EPIPE. One option to handle this is to switch to write(ln)!, but this will inject new requirements to handle Result where used, which can be onerous.

Create wrappers around the print macros to ignore EPIPE, and replace calls to the originals with them. Update main to ignore any EPIPEs returned from writeln! calls in subcommands.

We deliberately do not make this change to the auth login/logout subcommands as these are mutating the config. Failure to notify the user of the changes is fatal.

Before:

  $ oxide system networking switch-port-settings show | head -1
  switch0/qsfp0
  thread 'tokio-runtime-worker' panicked at library/std/src/io/stdio.rs:1021:9:
  failed printing to stdout: Broken pipe (os error 32)
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
  thread 'main' panicked at cli/src/main.rs:102:10:
  called `Result::unwrap()` on an `Err` value: JoinError::Panic(Id(15), ...)

After:

  $ oxide system networking switch-port-settings show | head -1
  switch0/qsfp0
wfchandler commented 1 month ago

Sorry to bombard you with reviews @ahl, are there any other maintainers I can spread these out to?

ahl commented 1 month ago

Sorry to bombard you with reviews @ahl, are there any other maintainers I can spread these out to?

I think I'm on the only one with state on why things are the way they are and where they're going. I feel like you're on a trajectory to shouldering some of that load.