Repository navigation
Conversation
--override-file rejects files without a valid environments array
|
Automated review A maintainer will still review this — treat the notes below as a starting point. 📌 Commit This PR fixes the inverted check in The fix is small and correct, and it closes both crash paths. The only behavior change is that Open findings: 🔴 0 blocking · 🟡 0 recommended · ⚪ 1 optional. Files with findings (1)
Generated automatically. React 👍 or 👎 to tell us whether this review helped, so we can improve these reviews. |
There was a problem hiding this comment.
See the review summary comment for the overview; the notes below are inline.
| if (!Array.isArray(environments) || !environments.every((group) => isObject(group?.resources))) { | ||
| throw new ToolkitError('MissingEnvironmentsArray', "Expected an 'environments' array whose entries each have a 'resources' object"); |
There was a problem hiding this comment.
⚪ Optional — One error message, Expected an 'environments' array whose entries each have a 'resources' object, now covers every kind of bad input: a missing key, a value that isn't an array, and a bad entry at any position. It never says what was actually found. A user with several environment entries can't tell which one failed. The repo's error-handling guidance asks messages to include the wrong value.
Suggested change: Split the check into two branches. If environments is not an array, say what was found instead, such as its type or the file's top-level keys. If an entry has no resources object, find it with findIndex and report its index plus its account/region. Start both messages with Expected an 'environments' array so the new tests still match, then regenerate the three new .ndjson snapshots.
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2201 +/- ##
==========================================
+ Coverage 92.53% 92.56% +0.03%
==========================================
Files 81 81
Lines 13238 13238
Branches 1917 1917
==========================================
+ Hits 12250 12254 +4
+ Misses 950 947 -3
+ Partials 38 37 -1
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:
|
Fixes #2200
cdk refactor --override-filereads a JSON file that tells the CLI how to resolve ambiguous resource moves. The check that should reject a malformed file is always true, so its error never fires. This came in with #679.The README example also uses a
mappingskey instead ofenvironments, so copying it gives a broken file.This PR:
environmentsis an array and every entry has aresourcesobject. Entries are checked because an entry withoutresourcescrashes the same function and does nothing anyway.environments.Before and after
Each example runs
cdk refactor --unstable=refactor --override-file=overrides.json.Input:
{ "mappings": [ { "account": "123456789012", "region": "us-east-1", "resources": { "Stack2.OldName": "Stack2.NewName" } } ] }Output:
environmentsvalueInput:
{ "environments": "" }Output
No error about the file. The CLI runs synth and carries on with the refactor.
resourcesInput:
{ "environments": [ { "account": "123456789012", "region": "us-east-1" } ] }Output
The README example works as written.
Testing
refusalstests inpackages/aws-cdk/test/commands/refactor.test.ts.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license