Skip to content

fix(aws-cdk-lib): toolkit is unaware of CDK app errors#37294

Merged
mergify[bot] merged 2 commits intomainfrom
huijbers/communicate-errors
Mar 20, 2026
Merged

fix(aws-cdk-lib): toolkit is unaware of CDK app errors#37294
mergify[bot] merged 2 commits intomainfrom
huijbers/communicate-errors

Conversation

@rix0rrr
Copy link
Copy Markdown
Contributor

@rix0rrr rix0rrr commented Mar 20, 2026

We want to know about the synth errors that happened in the CDK app in the Toolkit. In order to do that, we are doing the following things:

We print the error code between special markers. We have chosen the guillemet to print the error codes: «InvalidBucketName». It nicely braces the error, look visually appealing, and is uncommon enough that it is unlikely to appear in the output of a CDK app already accidentally.

The CLI will scan stdout and stderr for text between these markers. That approach is chosen because it will work regardless of whether the CDK app is executing via jsii or not (uncaughtException handlers will only work for direct Node programs, not jsii programs).

In order for this masterful scheme not to be foiled by a customer putting the following into their program:

console.log('«IveTrickedYouIntoCollectingCustomerContent»');

Whenever an error with an error code is constructed, we write the code to special file that is indicated by the CDK_ERROR_FILE environment variable (which will be set by the Toolkit). Only codes that appear in that file are eligible for scanning from stderr/stdout, so that we are not tricked into collecting customer content.

Why don't we just take the error code in that file as gospel? Because the exception could be caught and the program continued. That an Error object is produced doesn't mean it terminates the program.


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

We want to know about the synth errors that happened in the CDK app in
the Toolkit. In order to do that, we are doing the following things:

We print the error code between special markers. We have chosen the
guillemet to print the error codes: `«InvalidBucketName»`. It nicely
braces the error, look visually appealing, and is uncommon enough that
it is unlikely to appear in the output of a CDK app already
accidentally.

The CLI will scan `stdout` and `stderr` for text between these markers.
That approach is chosen because it will work regardless of whether the
CDK app is executing via jsii or not (`uncaughtException` handlers will
only work for direct Node programs, not jsii programs).

In order for this masterful scheme not to be foiled by a customer
putting the following into their program:

```ts
console.log('«IveTrickedYouIntoCollectingCustomerContent»');
```

Whenever an error with an error code is constructed, we write the code
to special file that is indicated by the `CDK_ERROR_FILE` environment
variable (which will be set by the Toolkit). Only codes that appear in
that file are eligible for scanning from `stderr`/`stdout`, so that
we are not tricked into collecting customer content.

Why don't we just take the error code in that file as gospel? Because
the exception could be caught and the program continued. That an Error
object is produced doesn't mean it terminates the program.
@rix0rrr rix0rrr requested a review from a team as a code owner March 20, 2026 10:27
@aws-cdk-automation aws-cdk-automation requested a review from a team March 20, 2026 10:27
@github-actions github-actions bot added the p2 label Mar 20, 2026
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Mar 20, 2026
Copy link
Copy Markdown
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

(This review is outdated)

@rix0rrr rix0rrr added pr-linter/exempt-test The PR linter will not require test changes pr-linter/exempt-integ-test The PR linter will not require integ test changes labels Mar 20, 2026
@aws-cdk-automation aws-cdk-automation dismissed their stale review March 20, 2026 10:58

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 20, 2026

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 20, 2026

Merge Queue Status

  • Entered queue2026-03-20 11:10 UTC · Rule: default-squash
  • Checks passed · in-place
  • Merged2026-03-20 11:41 UTC · at c05e775e6df40eedcc2fd797e7bb2537c929d560

This pull request spent 30 minutes 40 seconds in the queue, including 30 minutes 27 seconds running CI.

Required conditions to merge

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 20, 2026

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 093de92 into main Mar 20, 2026
18 of 19 checks passed
@mergify mergify bot deleted the huijbers/communicate-errors branch March 20, 2026 11:41
@github-actions
Copy link
Copy Markdown
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

contribution/core This is a PR that came from AWS. p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes pr-linter/exempt-test The PR linter will not require test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants