Skip to content

feat(cli): make --debug a multi-state flag (--debug=app, --debug=cli)#1604

Open
mrgrain wants to merge 5 commits into
mainfrom
mrgrain/feat/cli/multi-state-debug-flag
Open

feat(cli): make --debug a multi-state flag (--debug=app, --debug=cli)#1604
mrgrain wants to merge 5 commits into
mainfrom
mrgrain/feat/cli/multi-state-debug-flag

Conversation

@mrgrain
Copy link
Copy Markdown
Contributor

@mrgrain mrgrain commented Jun 5, 2026

When something unexpected happens during a cdk run, the natural instruction to give a user is simply "run again with --debug". Until now that single switch turned on both CDK_DEBUG (extra information from the CDK app during synthesis) and verbose AWS SDK tracing from the CLI at the same time, with no way to ask for just one. When troubleshooting it is often useful to know whether the problem lives in the CDK app or in the CLI itself, and the combined output makes that harder than it needs to be.

This change keeps --debug working exactly as before (it still debugs everything), but turns it into a multi-state flag so the output can be scoped. --debug=app only sets CDK_DEBUG for the app, and --debug=cli only enables AWS SDK tracing in the CLI. --debug=all is accepted as an explicit synonym for the bare flag. The intent is to preserve the simple "just add --debug" experience as the default, while giving people who already know where to look a way to cut down the noise.

The reason the flag is implemented as a string option rather than a boolean is that yargs has no option type that both carries an optional =value and behaves like a bare boolean. A plain string option would greedily consume the next token, so cdk deploy --debug MyStack would treat MyStack as the debug value and drop the stack selector. To avoid that regression a bare --debug is rewritten to --debug=all before the arguments reach yargs, which guarantees the flag always carries an explicit value and never swallows a following positional argument. This keeps cdk deploy --debug MyStack and cdk --debug deploy behaving as they do today. An unrecognized value (for example a typo) falls open to full debug output and emits a warning rather than failing the command.

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.

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

The --debug flag now accepts an optional target so users can scope debug
output. `--debug` (or `--debug=all`) debugs everything, `--debug=app` only
sets CDK_DEBUG for the app, and `--debug=cli` only enables verbose AWS SDK
tracing in the CLI. This keeps the simple "just run with --debug" experience
while allowing the granularity needed to isolate whether an issue is in the
CDK app or the CLI itself.

A bare --debug is rewritten to --debug=all before parsing so the underlying
string option never greedily consumes a following positional argument (e.g.
a stack name), preserving today's behavior for `cdk deploy --debug MyStack`
and `cdk --debug deploy`.
@aws-cdk-automation aws-cdk-automation requested a review from a team June 5, 2026 10:51
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

Dependency Review

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

Scanned Files

None

Frame the flag as a general troubleshooting tool and lead with the warning
that it slows everything down, rather than enumerating implementation details.
`commandLineArgumentsToSettings` types `argv.debug` as `unknown`, so the
debug helpers must accept `unknown` rather than `string | boolean | undefined`.
The implementations already narrow the value safely.
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
Comment on lines +105 to +111
if (!isRecognizedDebugValue(argv.debug)) {
await ioHost.defaults.warn(
`Unrecognized value '${argv.debug}' for --debug; enabling full debug output. ` +
`Expected no value, or one of: ${DEBUG_VALUE_CHOICES.map((c) => `--debug=${c}`).join(', ')}. ` +
'Note that --debug takes its value with "=" (e.g. --debug=app), otherwise the following argument may be consumed.',
);
}
Copy link
Copy Markdown
Contributor Author

@mrgrain mrgrain Jun 5, 2026

Choose a reason for hiding this comment

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

can we integrate this with the unknown options check? it feels different than yargs as well.

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.

I dropped the bespoke warning entirely rather than integrating it. After normalizeDebugArgs rewrites a bare --debug to --debug=all, the only way to hit an unrecognized value is an explicit --debug=typo, and interpretDebug already fails open to full debug — so a silent fail-open felt cleaner than a yargs-flavoured message. Happy to wire it into the unknown-options warning instead if you'd prefer an explicit heads-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.

2 participants