effect
effect copied to clipboard
Prints to stdout rather than stderr
What version of Effect is running?
effect@npm:2.0.0-next.62
What steps can reproduce the bug?
Follow the “minigit” example in README and invoke the command.
What is the expected behavior?
Messages to user are printed to stderr by default.
What do you see instead?
Messages are printed to stdout.
Additional information
Printing to stdout (unless specifically requested, such as with a --help flag) disrupts piping and is not conducive to writing well-behaved CLI commands.
I may have identified the culprit: cliApp’s run()’s onFailure() uses printDocs(), which (via platform/platform-node) delegates to Console.log(), which delegates to built-in console.log(), which writes to stdout.
If it works how I think it works, the proper solution would involve ensuring that only when help is requested that printDocs() (and therefore Console.log()) is used, while any other log/debug messages ultimately end up with Console.error() (which prints to stderr). A quick fix now may be to implement something along the lines of printError() (which would be the same as printDocs() except using Console.error()), and change the above onFailure() implementation to use that.
Hello @strogonoff ! Apologies for the late reply - I was not checking GitHub during the holidays. I think you've identified a reasonable solution to this issue. Is there any chance you would be willing to contribute a PR?
Otherwise I can probably get to this in the next few days 👍
Hi @IMax153! No problem. I might hold off the PR until I’m more comfortable with Effect, for now I’m a complete noob. After looking into the docs I suspect it might be possible for the end application to supply a changed implementation of Console and/or Effect.log without altering the upstream, I’ll look into that later as well (though defaulting to stderr for log output would still be desirable). Happy holidays!
@strogonoff - if you're still interested in contributing, you could also just change the required Console.log statements to Console.error statements. No alternative implementation of Console is required.
Otherwise, I can get to this soon :)