-
Notifications
You must be signed in to change notification settings - Fork 13
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
fix(cli): write notices to stderr or don't write them at all #188
base: main
Are you sure you want to change the base?
Conversation
On CI systems, the CDK CLI tries to avoid writing to `stderr` because there are a couple of CI systems that are commonly configured to fail if any output is written to `stderr`. That means all output, like notices, must go to `stdout`. Some commands (like `cdk synth` or `cdk bootstrap --show-template`) produce usable output on `stdout`, and these are commonly scripted, like piping their output to a file. However, because notices must go to `stdout`, these now interfere with the output of these commands. This needs a more thorough reworking of the CLI output streams, but there is a risk of affecting users who are currently relying on the fact that all output goes to `stdout`. In this PR, we are doing the first steps to solving this situation: - Notices will always go to `stderr`, so that they will never interfere with `stdout` anymore. - We try to detect what CI system we are running on, and we will completely suppress notices *unless* we determine that we are running on a CI system where it is "safe" to write to `sterr` (fail closed). "Safe" in this case means that the CI system doesn't come with an easy to toggle checkbox that makes commands fail based on what they print, instead of their exit codes. The only systems I'm aware of that have this checkbox are "Azure DevOps", and "TeamCity running PowerShell scripts". Even though we know the systems that are "unsafe", we will only show notices on systems known to be "safe". Fixes aws/aws-cdk#33589.
* | ||
* @default true | ||
*/ | ||
readonly shouldDisplay?: boolean; |
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.
Messages are now always emitted -- whether they are displayed or not is up to the IoHost.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #188 +/- ##
========================================
Coverage 85.02% 85.02%
========================================
Files 207 208 +1
Lines 35726 35919 +193
Branches 4605 4626 +21
========================================
+ Hits 30375 30540 +165
- Misses 5197 5232 +35
+ Partials 154 147 -7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
On CI systems, the CDK CLI tries to avoid writing to
stderr
because there are a couple of CI systems that are commonly configured to fail if any output is written tostderr
. That means all output, like notices, must go tostdout
.Some commands (like
cdk synth
orcdk bootstrap --show-template
) produce usable output onstdout
, and these are commonly scripted, like piping their output to a file.However, because notices must go to
stdout
, these now interfere with the output of these commands.This needs a more thorough reworking of the CLI output streams, but there is a risk of affecting users who are currently relying on the fact that all output goes to
stdout
.In this PR, we are doing the first steps to solving this situation:
stderr
, so that they will never interfere withstdout
anymore.sterr
(fail closed)."Safe" in this case means that the CI system doesn't come with an easy to toggle checkbox that makes commands fail based on what they print, instead of their exit codes. The only systems I'm aware of that have this checkbox are "Azure DevOps", and "TeamCity running PowerShell scripts".
Even though we know the systems that are "unsafe", we will only show notices on systems known to be "safe".
To make the existing
Notices
code play nice with theIoHost
, I needed to do a couple of things:IoHostEmitter
, to format messages that are sent to the IoHost. This converts strings or structured messages into anIoMessage
.NoticesFilter
class a proper class with anioHostEmitter
member.FakeIoHost
class for tests, to check for the messages we're emitting (as opposed to spying onstdout
or spying on thelogging
members)Fixes aws/aws-cdk#33589.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license