Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cli): use typed errors ToolkitError and AuthenticationError in CLI #32548

Merged
merged 31 commits into from
Dec 24, 2024

Conversation

sumupitchayan
Copy link
Contributor

@sumupitchayan sumupitchayan commented Dec 16, 2024

Closes #32347

This PR creates two new error types, ToolkitError and AuthenticationError and uses them in aws-cdk.

Checklist


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

Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
@aws-cdk-automation aws-cdk-automation requested a review from a team December 16, 2024 20:19
@github-actions github-actions bot added the p2 label Dec 16, 2024
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Dec 16, 2024
Copy link
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.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@aws-cdk-automation aws-cdk-automation added the pr/needs-cli-test-run This PR needs CLI tests run against it. label Dec 16, 2024
Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
@sumupitchayan sumupitchayan marked this pull request as ready for review December 16, 2024 23:22
@sumupitchayan sumupitchayan requested a review from a team as a code owner December 16, 2024 23:22
@sumupitchayan sumupitchayan changed the title chore(cli): use typed ToolkitError and AuthenticationError in CLI chore(cli): use typed errors ToolkitError and AuthenticationError in CLI Dec 16, 2024
Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
Copy link

codecov bot commented Dec 17, 2024

Codecov Report

Attention: Patch coverage is 54.16667% with 66 lines in your changes missing coverage. Please review.

Project coverage is 80.64%. Comparing base (5735e9e) to head (ee8204b).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #32548      +/-   ##
==========================================
+ Coverage   80.54%   80.64%   +0.10%     
==========================================
  Files         106      107       +1     
  Lines        6954     6996      +42     
  Branches     1287     1290       +3     
==========================================
+ Hits         5601     5642      +41     
  Misses       1175     1175              
- Partials      178      179       +1     
Flag Coverage Δ
suite.unit 80.64% <54.16%> (+0.10%) ⬆️

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

Components Coverage Δ
packages/aws-cdk 80.64% <54.16%> (+0.10%) ⬆️

Signed-off-by: Sumu <sumughan@amazon.com>
…onError func on the ToolkitError class

Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
Signed-off-by: Sumu <sumughan@amazon.com>
Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

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

Apologies if some of these questions were already asked/responded to by momo.

Also please configure the eslint rule for this package only to enforce we don't accidentally add new untyped errors.

I don't see where you've resolved this request

/**
* The type of the error, defaults to "toolkit".
*/
public readonly type: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this being used anywhere other than tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope (not yet at least) - I am also copying the implementation from ConstructError again here:

public abstract get type(): string;

Adding a type property is also the third instruction on Momo's ticket: #32347

Copy link
Contributor

Choose a reason for hiding this comment

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

again i wish you had a real reason beyond Momo telling you to. but this is fine, i suppose

*/
public readonly type: string;

constructor(message: string, type: string = 'toolkit') {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we restrict type to either toolkit or authentication? what was the decision making behind typing it as string?

Copy link
Contributor

Choose a reason for hiding this comment

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

also, should the constructor be private?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both ConstructError and ValidationError have public constructors:

constructor(msg: string, scope: IConstruct) {

I could make it an enum with string values? But I'm pretty sure Momo wanted a type property that is a string (third bullet point here): #32347

Copy link
Contributor

Choose a reason for hiding this comment

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

for all of these questions its my hope that you answer them with your reasons for why you've done something, not because Momo said to or because a prior implementation did so. Both of those things can be true, but you should at least know why you're doing it.

now for this case my question was a silly one. you have a public constructor because you are calling new ToolkitError everywhere

packages/aws-cdk/lib/toolkit/error.ts Show resolved Hide resolved
@kaizencc kaizencc dismissed mrgrain’s stale review December 23, 2024 17:33

stale, and i am the captain now

@sumupitchayan
Copy link
Contributor Author

Also please configure the eslint rule for this package only to enforce we don't accidentally add new untyped errors.

I don't see where you've resolved this request

cdklabs/eslint-rules#74

Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

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

I've approved. I will leave it to you to ensure that the CLI integ tests pass + to override the codecov failures

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: ee8204b
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sumupitchayan sumupitchayan added pr-linter/cli-integ-tested Assert that any CLI changes have been integ tested and removed pr/needs-cli-test-run This PR needs CLI tests run against it. labels Dec 24, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review December 24, 2024 20:14

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

@sumupitchayan sumupitchayan merged commit d48d77a into main Dec 24, 2024
17 of 22 checks passed
@sumupitchayan sumupitchayan deleted the sumughan/typed-errors-cli-toolkit branch December 24, 2024 20:18
Copy link

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 Dec 24, 2024
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/cli-integ-tested Assert that any CLI changes have been integ tested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typed Errors for cli/toolkit
4 participants