refactor(cli): make IoHost listener removers using-compatible - #1888
Merged
mrgrain merged 2 commits intoAug 24, 2026
Conversation
The remaining dynamic listeners in CdkToolkit (deploy's approval rewrite, destroy's level/decline/force listeners, the one-shot listing formatters) still required collecting dispose functions and calling them in a finally block. Listener registration methods on CliIoHost (on/once/rewrite/rewriteOnce/ respond/respondOnce) now return a DisposeListener: still a plain callable, but also a Disposable, so call sites can bind it with a `using` declaration and drop the try/finally entirely. Disposal happens at scope exit, including early returns and throws, and conditional listeners come for free since `using x = cond ? ... : undefined` skips disposal for undefined. The suppressMessages decorator uses the same mechanism internally.
Contributor
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## mrgrain/refactor/cli/suppress-messages-decorator #1888 +/- ##
====================================================================================
- Coverage 91.37% 91.34% -0.03%
====================================================================================
Files 80 80
Lines 12254 12261 +7
Branches 1749 1743 -6
====================================================================================
+ Hits 11197 11200 +3
- Misses 1021 1025 +4
Partials 36 36
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1887.
After the
suppressMessagesdecorator took over the static message drops, the remaining dynamic listeners inCdkToolkit— deploy's approval-framing rewrite, destroy's level override, decline-aborts, and--forceresponder, and the one-shot listing formatters — still required collecting dispose functions and calling them in afinallyblock, which is verbose and easy to get wrong.This change makes the listener registration methods on
CliIoHost(on,once,rewrite,rewriteOnce,respond,respondOnce) return aDisposeListener: still a plain callable remover, but also aDisposable, so call sites can bind it with ausingdeclaration and drop thetry/finallyentirely. Disposal then happens at scope exit, including early returns and throws, and conditional listeners come for free becauseusing x = cond ? ioHost.respondOnce(...) : undefinedsimply skips disposal forundefined. The repository already relies on TypeScript explicit resource management (usingfor telemetry timers), so no toolchain change is needed, and the return type change is backwards compatible for every existing caller. Most of the diff indeploy()is the mechanical de-indent from removing itstry/finallywrapper.Tested with a new unit test asserting the remover works as a
usingresource (listener active inside the block, gone at scope exit), plus the existing decorator and command suites; 234 tests across the affected suites pass and lint is clean.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license