-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Wrong command output #8498
Comments
I agree totally with this one. I keep doing Nice UNIX tricks, but not ergonomic at all. I feel I brought this up in another issue, but maybe it was just some rant on discord. |
I know @ethanfrey, yet POSIX tells us to print the least number of messages. Diagnostics and errors should always go to stderr. Only when a command's main purpose is to produce an output, then such output should go to stdout. I'd propose a different approach here: why don't we audit all commands and find which have streams wrongly redirected to stderr by default? |
@RiccardoM |
Looks like we need to do some grooming here. Ensure all query-based commands output to STDOUT. |
Is there any way to redirect logs to a file? We have waaaayyyyy too verbose log output and it dumps on stderr rather than a file. Most processes that log like crazy are meant to dump to a file rather than showing users |
I think a flag could be introduced, e.g. |
I wonder about the name. If it was only error log and not tendermint debug spam, I would not argue about pumping to stderr. If config files were supported (why was that removed?) we could just set the logfile in the config file and not worry about redirects on cli. Which is more or less how most long-living daemons I know work. Ideally, there could be 2 log files - one for real errors, one for the logs. No one complains about real errors going to stdout. Just mixing these logs everywhere hurts. |
I hear you, loud and clear. We should prioritize config file-driven CLI customization. IMHO it's more urgent than many other things. |
Just chiming in regarding logging to file. Quick workaround for systemd users, add the below to the .service file:
(and yes, everything is currently sent to stderr per this issue) |
Did this actually get fixed?
|
This issue still isn't resolved as far as I'm aware? We've been getting word on the Hub that people are still getting command output to stderr. |
A bunch of commands outputs got unexpectedly switched to stderr in the SDK v0.44 upgrade |
Anyone here is already taking a look at this? If not, we can assign someone on Regen on this. |
@ValarDragon do you have any idea on which commands outputs got switched to stderr ? |
I tested a few CLI subcommands with JSON outputs and piping them to jq, they all work fine on master. |
@czarcas7ic would have a better idea than me. The big one that we had to work around was state exports |
Currently the only one I know off the top of my head is when we do state exports like so:
In the osmosis installer, I muted both stdout and stderr during all CLI subcommands since I wasn't sure which were mixed up. Soon I'm going to go back through and enable all stderrs and will report back here which ones output stdout instead. |
@AmauryM do you think we should wait until @czarcas7ic reports back here ? |
I've tried testing this with |
Proposing to close this, since it seems it works in v0.45 and master. If there's a strong will to backport this to v0.44, let us know here. |
re-opening here this issue isn't resolved. I think we should do @alessio 's suggestion of:
The ones collected in the gaia issue are as follows:
|
@glnro was going to add one more |
cc @Pantani |
Not able to reproduce with the
|
## Description This PR introduces the `cmdtest` package, offering a lightweight wrapper around cobra commands to simplify testing CLI utilities. I backfilled tests for the `version` command, which was an example of a very simple test setup; and for the `export` command, which was more involved due to the server and client context requirements. I did notice that there are some existing tests for some utilities, but the `cmdtest` package follows a simple pattern that has been easy to use successfully in [the relayer](https://github.com/cosmos/relayer/blob/main/internal/relayertest/system.go) and in other projects outside the Cosmos ecosystem. While filling in these tests, I started removing uses of `cmd.Print`, as that is the root cause of issues like #8498, #7964, #15167, and possibly others. Internal to cobra, the print family of methods write to `cmd.OutOrStderr()` -- meaning that if the authors call `cmd.SetOutput()` before executing the command, the output will be written to stdout as expected; otherwise it will go to stderr. I don't understand why that would be the default behavior, but it is probably too late to change from cobra's side. Instead of `cmd.Print`, we prefer to `fmt.Fprint(cmd.OutOrStdout())` or `fmt.Fprint(cmd.ErrOrStderr())` as appropriate, giving an unambiguous destination for output. And the new tests collect those outputs in plain `bytes.Buffer` values so that we can assert their content appropriately. In the longer term, I would like to deprecate and eventually remove the `testutil` package's `ApplyMockIO` method and its `BufferWriter` and `BufferReader` types, as they are unnecessary indirection when a simpler solution exists. But that can wait until `cmdtest` has propagated through the codebase more. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] ~~provided a link to the relevant issue or specification~~ - [x] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed all author checklist items have been addressed - [ ] confirmed that this PR does not change production code
Summary of Bug
Most of the commands print their outputs to
stderr
instead ofstdout
, making it harder to pipe with other utilities (such asjq
).Version
v0.40.1
Steps to Reproduce
simd status
)jq
This will return the default output of the command, instead of the output of
jq
. A workaround is to redirectstderr
tostdout
for while running the command:Possible solution
Taking a look at the commands code I noticed that, although many commands use the
cmd.Print
methods, only few correctly set their output usingcmd.SetOut
. This causes thecmd.Print
to print the output usingstderr
, as per documentation:// Println is a convenience method to Println to the defined output, fallback to Stderr if not set.
I think that a possible solution could be to add the following lines to the
app.go
'sinitRootCmd
function:This would make sure that by default all commands are set to have their output to
stdout
, with the ability to override it later.For Admin Use
The text was updated successfully, but these errors were encountered: