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

fix: corrrectly return 4XX errors instead of 5XX errors #24519

Merged
merged 23 commits into from
Dec 27, 2023

Conversation

davidby-influx
Copy link
Contributor

HTTP 5XX errors were being returned incorrectly from
BoltDB errors that were really bad requests like names
that were too long for buckets, users, and organizations.
Map BoltDB errors to correct Influx errors and return
4XX errors where appropriate.

@davidby-influx davidby-influx self-assigned this Dec 19, 2023
@davidby-influx davidby-influx changed the title Corrrectly return 4XX errors instead of 5XX errors fix: corrrectly return 4XX errors instead of 5XX errors Dec 19, 2023
@davidby-influx davidby-influx marked this pull request as ready for review December 19, 2023 19:18
@@ -43,7 +43,7 @@ func (s *Store) Update(ctx context.Context, fn func(kv.Tx) error) error {
}

func (s *Store) setup() error {
return s.Update(context.Background(), func(tx kv.Tx) error {
err := s.Update(context.Background(), func(tx kv.Tx) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you make this change intending to add further changes in this code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had changes there and backed them out. I will revert this.

@@ -35,7 +35,8 @@ func (h ErrorHandler) HandleHTTPError(ctx context.Context, err error, w http.Res

code := errors2.ErrorCode(err)
var msg string
if _, ok := err.(*errors2.Error); ok {
var eTmp *errors2.Error
if ok := errors.As(err, &eTmp); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why As with a tmp var instead of Is? I noticed this pattern in a few places, so I assume its intentional but I'm not sure why.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For errors.Is you have to provide a concrete object that is matched against for equality. In errors.As you are trying to find something that is assignable to the target. Since the influx Error struct actually can represent tons of errors, assignable is all we really want. I don't want field-by-field comparison.

@@ -217,13 +218,13 @@ func (s *Store) UpdateOrg(ctx context.Context, tx kv.Tx, id platform.ID, upd inf
}

if err := idx.Delete(organizationIndexKey(u.Name)); err != nil {
return nil, ErrInternalServiceError(err)
return nil, errors.ErrInternalServiceError(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

In this file, you have some ErrInternalServiceError where you add the errors.WithErrorOp and some that you don't. Should they be consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently not, judging by the existing code. Some errors in, for example, GetOrgByName, return op codes for that call but some of the actions within CreateOrg have their own private op codes, like kv/MarshalOrg. And some OS errors bubble up without op codes.

I need to consider how much time we want to spend on rationalizing this...

@@ -57,7 +57,7 @@ func (s *Store) uniqueBucketName(ctx context.Context, tx kv.Tx, oid platform.ID,
}

// any other error is some sort of internal server error
return ErrInternalServiceError(err)
return errors.ErrInternalServiceError(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to my question in storage_org.go, do you want the errors.WithErrorOp on the errors here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

uniqueBucketName is called from CreateBucket and UpdateBucket so there is no single operation to use. It might be better to set the operation in the caller.

@@ -208,11 +209,11 @@ func (s *Store) CreateUser(ctx context.Context, tx kv.Tx, u *influxdb.User) erro
}

if err := idx.Put([]byte(u.Name), encodedID); err != nil {
return ErrInternalServiceError(err)
return errors.ErrInternalServiceError(err, errors.WithErrorOp(influxdb.OpCreateUser))
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question as storage_org.go

@davidby-influx davidby-influx merged commit a3fd489 into main-2.x Dec 27, 2023
26 checks passed
@davidby-influx davidby-influx deleted the DSB_5_to_4 branch December 27, 2023 16:21
davidby-influx added a commit that referenced this pull request Dec 27, 2023
HTTP 5XX errors were being returned incorrectly from
BoltDB errors that were actually bad requests, e.g.,
names that were too long for buckets, users, and
organizations. Map BoltDB errors to correct Influx
errors and return 4XX errors where appropriate. Also
add op codes to more errors

(cherry picked from commit a3fd489)
davidby-influx added a commit that referenced this pull request Dec 28, 2023
)

HTTP 5XX errors were being returned incorrectly from
BoltDB errors that were actually bad requests, e.g.,
names that were too long for buckets, users, and
organizations. Map BoltDB errors to correct Influx
errors and return 4XX errors where appropriate. Also
add op codes to more errors

(cherry picked from commit a3fd489)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api area/2.x OSS 2.0 related issues and PRs kind/bug team/edge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants