Skip to content

Conversation

@mrgrain
Copy link
Contributor

@mrgrain mrgrain commented Apr 22, 2025

Fixes #370
Fixes #440

Previously when the --no-notices option was passed, the CLI would still attempt to refresh notices in the background. This is unnecessary and an unexpected behavior to users, especially when running the CLI in environments with no internet access.

On the other hand, running the explicit cdk notices command did previously not fail if the command failed to refresh notices. Instead the command would pretend no notices are found and complete successfully.

This PR updates the code to not refresh notices when notices are disabled. Unless the explicit cdk notices command is called, which will always refresh and now error if fetching notices fails. It also removes a double refresh of the notices (which didn't have an effect because they were cached, but still).

cdk notices with an error now looks like this:

image

Before the command would incorrectly and silently succeed and not show any notices:

image

Only when run with the -v flag, it would hint at the failure:

$ cdk notices -v
...
[12:38:29] Could not refresh notices: Error: getaddrinfo ENOTFOUND cli.cdk.dev-tools

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 April 22, 2025 09:43
@github-actions github-actions bot added bug effort/medium 1-3 days of effort p2 labels Apr 22, 2025
@codecov-commenter
Copy link

codecov-commenter commented Apr 22, 2025

Codecov Report

Attention: Patch coverage is 42.85714% with 12 lines in your changes missing coverage. Please review.

Project coverage is 79.17%. Comparing base (bd4ad74) to head (d8107f7).

Files with missing lines Patch % Lines
packages/aws-cdk/lib/cli/cli.ts 40.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #399      +/-   ##
==========================================
- Coverage   79.25%   79.17%   -0.08%     
==========================================
  Files          54       54              
  Lines        6897     6910      +13     
  Branches      772      773       +1     
==========================================
+ Hits         5466     5471       +5     
- Misses       1413     1421       +8     
  Partials       18       18              
Flag Coverage Δ
suite.unit 79.17% <42.85%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rix0rrr
Copy link
Contributor

rix0rrr commented Apr 22, 2025

This is unexpected to users and prevents the CLI from running in environments with no internet access.

If this prevents the CLI from running in those environments we have even more problems, because the behavior should be that failures get swallowed. This is not critical but best-effort behavior, so it's fine.

It's just for cdk notices that a fetch failure should be fatal.

@mrgrain
Copy link
Contributor Author

mrgrain commented Apr 22, 2025

This is unexpected to users and prevents the CLI from running in environments with no internet access.

If this prevents the CLI from running in those environments we have even more problems, because the behavior should be that failures get swallowed. This is not critical but best-effort behavior, so it's fine.

It's just for cdk notices that a fetch failure should be fatal.

Ah yes, you are correct. CachedDataSource makes the call non-fatal. I had only looked at the WebsiteNoticeDataSource code. But that means it's also not fatal for cdk notices.

@rix0rrr
Copy link
Contributor

rix0rrr commented Apr 22, 2025

But that means it's also not fatal for cdk notices.

We could make a distinction in the internal state between "successful fetch with no notices" and "no fetch", and do something like:

notices.assertLastFetchSuccessful();

In the handling of cdk notices.

@mrgrain mrgrain force-pushed the mrgrain/fix-no-notices-does-refresh branch from dcd0105 to 5122208 Compare May 1, 2025 11:41
@mrgrain mrgrain force-pushed the mrgrain/fix-no-notices-does-refresh branch from 6cfb393 to e88e326 Compare May 1, 2025 13:54
github-merge-queue bot pushed a commit that referenced this pull request May 2, 2025
No code changes. This is in preparation of #399 to make the diff more
manageable.

---
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache-2.0 license
@mrgrain mrgrain force-pushed the mrgrain/fix-no-notices-does-refresh branch from a057085 to 4eaebec Compare May 2, 2025 13:21
@mrgrain mrgrain changed the title fix(cli): calling cli with --no-notices makes an unexpected network call to refresh notices fix(cli): cdk notices ignores failure fetching notices and calling cli with --no-notices makes an unexpected network call May 2, 2025
@mrgrain mrgrain changed the title fix(cli): cdk notices ignores failure fetching notices and calling cli with --no-notices makes an unexpected network call fix(cli): cdk notices ignores failures and calling cli with --no-notices makes an unexpected network call May 2, 2025
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this file I mostly make the error messages consistent. Variations of Failed to fetch notices are moved to one level up. Any errors from this file will show up as the cause printed in yellow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AI generated. Needed an easy way to make errors more human.

Comment on lines 119 to 117
const refreshNotices = (async () => {
if (shouldDisplayNotices) {
try {
return await notices.refresh();
} catch (e: any) {
await ioHelper.notify(IO.DEFAULT_TOOLKIT_DEBUG.msg(`Could not refresh notices: ${e}`));
}
}
})();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

refresh now throws

const cause = ensureError(err.cause);
console.error(chalk.yellow(cause.message));
printTrace(err, debug);
printTrace(cause, debug);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unrelated bug, but previously in dev mode we would print the stack trace of the parent error twice.

@aws aws deleted a comment from github-actions bot May 2, 2025
@mrgrain mrgrain force-pushed the mrgrain/fix-no-notices-does-refresh branch from 4eaebec to 70eab93 Compare May 2, 2025 13:45
@mrgrain mrgrain marked this pull request as ready for review May 2, 2025 13:46
@mrgrain mrgrain changed the base branch from main to mrgrain/refactor/notices/auto-detect May 5, 2025 11:27
Base automatically changed from mrgrain/refactor/notices/auto-detect to main May 5, 2025 11:50
@mrgrain mrgrain temporarily deployed to integ-approval May 5, 2025 11:51 — with GitHub Actions Inactive
@aws-cdk-automation aws-cdk-automation added this pull request to the merge queue May 5, 2025
Merged via the queue into main with commit 6b16a21 May 5, 2025
20 checks passed
@aws-cdk-automation aws-cdk-automation deleted the mrgrain/fix-no-notices-does-refresh branch May 5, 2025 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug effort/medium 1-3 days of effort p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(cli): cdk notices ignores any failure fetching notices CLI: --no-notices won't supress call to https://cli.cdk.dev-tools.aws.dev/notices.json

4 participants