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

s3 publisher errors should root from base error #4401

Closed
wants to merge 18 commits into from
Closed

Conversation

udsamani
Copy link
Contributor

This PR aims at standardizing S3 Errors to use the BaseError Present

@udsamani udsamani requested a review from wdbaruni September 11, 2024 01:46
@udsamani udsamani changed the title S3 Errors Fix s3 publisher all errors should root from base error Sep 11, 2024
@udsamani udsamani changed the title s3 publisher all errors should root from base error s3 publisher errors should root from base error Sep 11, 2024
@udsamani udsamani self-assigned this Sep 11, 2024
Copy link
Member

@frrist frrist left a comment

Choose a reason for hiding this comment

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

good stuff, left a few comments/thoughts.

Comment on lines -150 to +151
return err
return errors.New(err.Error())
Copy link
Member

Choose a reason for hiding this comment

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

please revert this, either do:
return err
or
return fmt.Errorf("<helpful message>: %w", err)

Comment on lines -91 to +92
return fmt.Errorf("could not get job %s: %w", jobID, err)
return err
Copy link
Member

Choose a reason for hiding this comment

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

I assume this is being removed since the Get method's error already contains a detailed description?

Comment on lines -163 to +164
return err
return errors.New(err.Error())
Copy link
Member

Choose a reason for hiding this comment

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

similar comment as stated elsewhere.

@@ -33,7 +34,7 @@ func DownloadResultsHandler(
JobID: jobID,
})
if err != nil {
Fatal(cmd, fmt.Errorf("could not get results for job %s: %w", jobID, err), 1)
return errors.New(err.Error())
Copy link
Member

Choose a reason for hiding this comment

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

similar comment as stated elsewhere.

Comment on lines -179 to +181
return job, bacerrors.NewJobNotFound(jobID)
return job, apimodels.NewJobNotFound(jobID)
Copy link
Member

Choose a reason for hiding this comment

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

I think we can used jobstore.NewErrJobNotFound here, no?

Comment on lines +64 to +66
if resp.StatusCode == http.StatusUnauthorized {
return apimodels.NewUnauthorizedError("invalid token")
}
Copy link
Member

Choose a reason for hiding this comment

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

Do you think it would be cleaner to do:

return apimodels.NewAPIError(http.StatusUnauthorized, "invalid token")

instead?

The methods like NewBadRequestError, NewForbiddenError, etc. feel like unnecessary wrapping.

Comment on lines +9 to +12
const (
JOB_STORE_COMPONENT = "JBS"
BOLTDB_COMPONENT = "BDB"
)
Copy link
Member

Choose a reason for hiding this comment

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

What is the different between these components? BOLTDB_COMPONENT seems like an implementation detail.
Also, similar comment here regarding naming.

return apimodels.ErrInvalidToken
} else if err != nil {

_, resp, err := c.doRequest(ctx, http.MethodGet, endpoint, r) //nolint:bodyclose // this is being closed
Copy link
Member

Choose a reason for hiding this comment

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

remember to close the body, there is a potential for it to not get closed here if the status code isn't OK

if apiError != nil {
return apiError
}

defer resp.Body.Close()
Copy link
Member

Choose a reason for hiding this comment

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

move this up as other comment suggests.


const S3_PUBLISHER_COMPONENT = "S3PUB"

func NewErrBadS3Request(msg string) *models.BaseError {
Copy link
Member

Choose a reason for hiding this comment

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

nit on naming here and elsewhere, would prefer:
NewBadS3RequestError

and more generally:
New<Type>Error

@udsamani udsamani closed this Sep 12, 2024
wdbaruni added a commit that referenced this pull request Sep 19, 2024
- introduced by #4366, we need to close the body only if there isn't an
error, else the body is nil and panics. Mentioned here
#4401 (comment)

Co-authored-by: frrist <[email protected]>
Co-authored-by: Walid Baruni <[email protected]>
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