-
Couldn't load subscription status.
- Fork 19
Ignore EPIPE in CLI #746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore EPIPE in CLI #746
Conversation
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 `EPIPE`s
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
83b71eb to
8eb27f3
Compare
|
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good; feel free to merge
With f472bce (Ignore EPIPE in CLI (#746), 2024-07-17) we added the `_nopipe` variants of the `(e)print(ln)!` macros to avoid panicking when piping to head(1). However, we do not systematically enforce their use, which will inevitably lead inconsistent usage within the project. Add `clippy` lints to ban use of the print macros in all non-test code. Either the `_nopipe` variants should be used when we don't care if the input is read, or `write!` when the information is crucial, such as an interactive session.
With f472bce (Ignore EPIPE in CLI (#746), 2024-07-17) we added the `_nopipe` variants of the `(e)print(ln)!` macros to avoid panicking when piping to head(1). However, we do not systematically enforce their use, which will inevitably lead inconsistent usage within the project. Add `clippy` lints to ban use of the print macros in all non-test code. Either the `_nopipe` variants should be used when we don't care if the input is read, or `write!` when the information is crucial, such as an interactive session.
Piping command output to a process that performs a partial read before closing the pipe, such as
head, will cause anEPIPEto be raised on the next write attempt. The standard(e)print(ln)!macros will panic on any errors when writing, includingEPIPE. One option to handle this is to switch towrite(ln)!, but this will inject new requirements to handleResultwhere used, which can be onerous.Create wrappers around the print macros to ignore
EPIPE, and replace calls to the originals with them. Updatemainto ignore anyEPIPEs returned fromwriteln!calls in subcommands.We deliberately do not make this change to the
auth login/logoutsubcommands as these are mutating the config. Failure to notify the user of the changes is fatal.Before:
After:
$ oxide system networking switch-port-settings show | head -1 switch0/qsfp0