Skip to content

feat(cli): add --debug-app and --debug-cli flags#1604

Draft
mrgrain wants to merge 1 commit into
mainfrom
mrgrain/feat/cli/multi-state-debug-flag
Draft

feat(cli): add --debug-app and --debug-cli flags#1604
mrgrain wants to merge 1 commit into
mainfrom
mrgrain/feat/cli/multi-state-debug-flag

Conversation

@mrgrain

@mrgrain mrgrain commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

When something goes wrong during a cdk run, the usual advice is "run again with --debug". Until now that single switch turned on both extra output from the CDK app during synthesis (via CDK_DEBUG) and verbose AWS SDK tracing from the CLI at the same time, with no way to ask for just one. When you are troubleshooting it is often useful to know whether the problem lives in the CDK app or in the CLI itself, and the combined firehose of output makes that harder than it needs to be.

This adds two more granular flags, --debug-app and --debug-cli, while keeping --debug as the broad "turn everything on" switch that implies both. --debug-app only enables app debugging (sets CDK_DEBUG, which logs additional information during synthesis such as creation stack traces of tokens, and slows synthesis down), and --debug-cli only enables verbose AWS SDK tracing in the CLI. The intent is to keep the simple "just add --debug" experience as the default while letting people who already know where to look cut down the noise.

All three are plain boolean flags. An earlier iteration modelled this as a value-carrying --debug=app|cli, but yargs cannot offer an optional flag value without greedily consuming the following token (so cdk deploy --debug MyStack would lose the stack selector), and working around that required rewriting the argument list before parsing. Three booleans avoid that problem entirely.

App and CLI debugging are tracked as separate configuration settings (debugApp / debugCli) so they can be reasoned about independently. App debugging continues to drive the CDK_DEBUG environment variable for the synthesized app; the previous debug setting is still honored as a fallback so existing configurations keep working.

Finally, cdk doctor now reports the resolved CLI configuration — whether app and CLI debugging are enabled, and the current verbosity level — so it is easy to confirm what the CLI thinks it was asked to do.

Fixes #

Checklist

  • This change contains a major version upgrade for a dependency and I confirm all breaking changes are addressed
    • Release notes for the new version:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team June 5, 2026 10:51
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Comment thread packages/aws-cdk/lib/cli/util/debug.ts Outdated
Comment thread packages/aws-cdk/lib/cli/cli.ts Outdated
Comment thread packages/aws-cdk/lib/cli/cli.ts Outdated
@rix0rrr

rix0rrr commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

This is additive rather than breaking: a bare --debug is unchanged, and --debug=app/--debug=cli previously coerced to false under the boolean option, so they did nothing before.

At the expense of losing the way to write --debug app I suppose? It must be written as --debug=app ?

@mrgrain mrgrain marked this pull request as draft June 10, 2026 13:02
auto-merge was automatically disabled June 10, 2026 13:02

Pull request was converted to draft

Comment thread packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/environment.ts Outdated
Comment thread packages/aws-cdk/lib/cli/cli-config.ts Outdated
Comment thread packages/aws-cdk/lib/cli/cli.ts Outdated
Comment thread packages/aws-cdk/lib/cli/cli.ts Outdated
Comment thread packages/aws-cdk/lib/cli/user-input.ts Outdated
Comment thread packages/aws-cdk/lib/commands/doctor.ts
Comment thread packages/aws-cdk/lib/commands/doctor.ts Outdated

@mrgrain mrgrain left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there, but the whole--debug implies both targets things needs better modelling. we can change the configuration generator package.

@mrgrain

mrgrain commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Reworked the --debug implication into the config generator as you suggested. @aws-cdk/user-input-gen now supports an option-level implies field, and debug declares implies: ['debug-app', 'debug-cli']. The generator emits a yargs middleware (yargsImplies) that switches the implied flags on during parsing, so by the time anything reads argv, debugApp/debugCli are already true — no hand-written argv.debug || ... anywhere. A config-file debug: true is normalized to both targets when settings are assembled, and environment.ts keys CDK_DEBUG off debugApp only. All comment threads addressed and resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is always shown, removing the double up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants