fix(cli): cdk list pollutes stdout with synthesis time#1637
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
| // Not `synthAndMeasure`: `list` is a read-only query and its synth-time message | ||
| // would pollute stdout when the result is piped (e.g. `list --json | jq`). | ||
| await using assembly = await assemblyFromSource(ioHelper, cx); |
There was a problem hiding this comment.
I would say this is the wrong fix.
Wouldn't it make more sense to suppress the "synthesis time" message in --json mode, or something to that effect?
Either that, or say "this is query and therefore we're not printing anything other than the output" (which you said on Slack that I also like), but I wouldn't implement that by bypassing the entire method synthAndMeasure method; all synths get routed through that function and I would like to keep it that way. The measuring is NOT JUST printing to the screen, it's also measuring internally.
Maybe we suppress printing by the the IoHost instead or something.
This fix should be about what gets printed, not about what gets done.
There was a problem hiding this comment.
Updated to follow the same pattern as the rewriteOnce(I2901) line right above, a host-side listener on a library message. That one reshapes the listing, this one suppresses the synth-time line via once(I1000, () => ({ preventDefault: true })). synthAndMeasure stays untouched so synth is still measured, only what's printed changes.
| // Not `synthAndMeasure`: `list` is a read-only query and its synth-time message | ||
| // would pollute stdout when the result is piped (e.g. `list --json | jq`). | ||
| await using assembly = await assemblyFromSource(ioHelper, cx); |
Fixes #1632
cdk listprints✨ Synthesis time: X.XXsto stdout in CI mode (regressed in 2.1127.0). That extra line shows up in machine-readable output, so pipingcdk listinto a parser (e.g.cdk list --json | jq) breaks.For example,
$ cdk list --jsonin CI mode gives you:The parser only expects the stack list, so the
Synthesis timeline makes it fail.#1603 routed
cdk listthrough the toolkit-liblistaction, which synthesizes viasynthAndMeasure. That helper opens a timing span, and ending the span emitsCDK_TOOLKIT_I1000("Synthesis time"). In CI mode the CLI sends non-error messages to stdout, so the line lands next to the listing.The CLI now drops the synth-time message (CDK_TOOLKIT_I1000) on the list path before it's written, so stdout carries only the listing.
$ cdk list --json# after fix, CI modeTesting
cdk listregisters a one-shot suppressor forCDK_TOOLKIT_I1000, so the synth-time line is not printed.cdk lsin CI produces stdout with only the stack listing, no synthesis-time line.cdk list --jsonin CI → clean stdout).Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license