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

Add clearer error for VPP token constraint failure #21967

Merged
merged 4 commits into from
Sep 11, 2024

Conversation

dantecatalfamo
Copy link
Member

@dantecatalfamo dantecatalfamo commented Sep 10, 2024

#21890

If some of the following don't apply, delete the relevant line.

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.
  • Added/updated tests
  • Manual QA for all new/changed functionality

@dantecatalfamo dantecatalfamo changed the title Add checked error for vpp token constraint failures Add clearer error for VPP token constraint failure Sep 11, 2024
@dantecatalfamo dantecatalfamo marked this pull request as ready for review September 11, 2024 13:25
@dantecatalfamo dantecatalfamo requested a review from a team as a code owner September 11, 2024 13:25
@@ -858,6 +860,17 @@ func (ds *Datastore) UpdateVPPTokenTeams(ctx context.Context, id uint, teams []u
})

if err != nil {
mysqlErr := &mysql.MySQLError{}
// https://dev.mysql.com/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_dup_entry
if errors.As(err, &mysqlErr) && mysqlErr.Number == 1062 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! Heads up: we have an IsDuplicate function in the mysql/errors.go file that does this check, can probably use that

Copy link
Member Author

Choose a reason for hiding this comment

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

Dang good to know

Copy link

codecov bot commented Sep 11, 2024

Codecov Report

Attention: Patch coverage is 58.33333% with 10 lines in your changes missing coverage. Please review.

Project coverage is 64.93%. Comparing base (9fedb59) to head (181bd3c).
Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
server/fleet/mdm.go 50.00% 4 Missing ⚠️
server/datastore/mysql/vpp.go 72.72% 2 Missing and 1 partial ⚠️
server/service/appconfig.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #21967      +/-   ##
==========================================
- Coverage   64.96%   64.93%   -0.03%     
==========================================
  Files        1492     1492              
  Lines      116166   116670     +504     
  Branches     3466     3466              
==========================================
+ Hits        75467    75760     +293     
- Misses      33694    33853     +159     
- Partials     7005     7057      +52     
Flag Coverage Δ
backend 66.16% <58.33%> (-0.04%) ⬇️

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.

@@ -858,6 +860,17 @@ func (ds *Datastore) UpdateVPPTokenTeams(ctx context.Context, id uint, teams []u
})

if err != nil {
var mysqlErr *mysql.MySQLError
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an example of how a duplicate error is handed elsewhere in the codebase, sorry should have linked this originally! IsDuplicate does the cast to a mysql.MySQLError, so that should be ok to leave out here.

https://github.com/fleetdm/fleet/blob/main/server/datastore/mysql/app_configs.go#L172-L175

Copy link
Member Author

Choose a reason for hiding this comment

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

I do the cast so I can extract the ID of the duplicate below, but good to know as well!

}

func (e ErrVPPTokenTeamConstraint) Error() string {
return fmt.Sprintf("Error: %q team already has a VPP token. Each team can only have on VPP token.", e.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: smol typo

can only have one VPP token

Copy link
Member Author

Choose a reason for hiding this comment

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

Merci beaucoup

@dantecatalfamo
Copy link
Member Author

The integration test doesn't fail when I run it locally, I'm going to try running the whole suite locally to see if I can find the issue

@dantecatalfamo
Copy link
Member Author

The integration test doesn't fail when I run it locally, I'm going to try running the whole suite locally to see if I can find the issue

Everything passes without issue, very interesting

@dantecatalfamo dantecatalfamo merged commit 8ad0d59 into main Sep 11, 2024
24 of 25 checks passed
@dantecatalfamo dantecatalfamo deleted the vpp-token-constraint-error branch September 11, 2024 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants