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

Remove github.com/zeebo/errs dependency #5716

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rturner3
Copy link
Collaborator

@rturner3 rturner3 commented Dec 14, 2024

We don't really use this dependency for much other than to group some errors together with a common error message prefix. The same can now be accomplished with a couple custom error types and the errors standard library package.

This package also wasn't consistently adopted throughout the project, so at this point it's probably better to just rely on the standard library functionality, since it's sufficient for the project's use cases.

Fixes #5631.

We don't really use this dependency for much other than to group some
errors together with a common error message prefix. The same can now
be accomplished with a couple custom error types and the `errors`
standard library package.

This package also wasn't consistently adopted throughout the project, so
at this point it's probably better to just rely on the standard library
functionality, since it's sufficient for the project's use cases.

Signed-off-by: Ryan Turner <ryan.turner253@icloud.com>
@MarcosDY MarcosDY self-assigned this Dec 17, 2024
}
if c.JWTIssuer != "" {
jwtIssuer, err := url.Parse(c.JWTIssuer)
if err != nil || jwtIssuer.Scheme == "" || jwtIssuer.Host == "" {
return nil, errs.New("the jwt_issuer url could not be parsed")
return nil, errors.New("the jwt_issuer url could not be parsed")
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we also include the error in here and maybe the jwtIssuer?

Copy link
Collaborator

Choose a reason for hiding this comment

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

if that is the case, we may need to have 2 if one for err != nil and another for issuer

@@ -300,7 +300,7 @@ func migrateDB(db *gorm.DB, dbType string, disableMigration bool, log logrus.Fie
dbCodeVersion, err := getDBCodeVersion(*migration)
if err != nil {
log.WithError(err).Error("Error getting DB code version")
return sqlError.New("error getting DB code version: %v", err)
return newSQLError("error getting DB code version: %v", err)
Copy link
Contributor

@sorindumitru sorindumitru Dec 26, 2024

Choose a reason for hiding this comment

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

Would this be better in any way with newWrappedSQLError(fmt.Errorf("error getting DB code version: %w", err))? I think it might be better for use with errors.Is.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm worried if that we create a wrapped error here, that may be changing current behavior

@@ -250,6 +250,7 @@ func (s *PluginSuite) TestBundleCRUD() {

// fetch non-existent
fb, err := s.ds.FetchBundle(ctx, "spiffe://foo")
s.T().Logf("err type: %T", err)
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 a debug leftover?

Comment on lines +17 to +19
if err := cs[i].Close(); err != nil {
errs = errors.Join(errs, err)
}
Copy link

Choose a reason for hiding this comment

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

Join() discards nil error values so you should be able to do:

Suggested change
if err := cs[i].Close(); err != nil {
errs = errors.Join(errs, err)
}
errs = errors.Join(errs, cs[i].Close())

Comment on lines +17 to +31
func newSQLError(fmtMsg string, args ...any) error {
return &sqlError{
msg: fmt.Sprintf(fmtMsg, args...),
}
}

func newWrappedSQLError(err error) error {
if err == nil {
return nil
}

return &sqlError{
err: err,
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can you move private functions to the end of the file?

return fmt.Sprintf("%s: %s", datastoreSQLErrorPrefix, s.msg)
}

func (s *sqlError) Is(err error) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

it is no clear to me, the use of this function,
this sqlError has 2 "states" when you use msg or when you use err
but here we are only validating msg,
may we validate both?

Comment on lines +15 to +17
assert.True(t, errors.As(err, &sErr))

assert.True(t, errors.Is(err, &sqlError{
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT: use assert.ErrorIs and assert.ErrorAS (same apply to all tests)

@@ -300,7 +300,7 @@ func migrateDB(db *gorm.DB, dbType string, disableMigration bool, log logrus.Fie
dbCodeVersion, err := getDBCodeVersion(*migration)
if err != nil {
log.WithError(err).Error("Error getting DB code version")
return sqlError.New("error getting DB code version: %v", err)
return newSQLError("error getting DB code version: %v", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm worried if that we create a wrapped error here, that may be changing current behavior

}

if !opts.ParseTime {
return sqlError.Wrap(errors.New("invalid mysql config: missing parseTime=true param in connection_string"))
return newWrappedSQLError(errors.New("invalid mysql config: missing parseTime=true param in connection_string"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

may we use newSQLError error here?

}
if c.JWTIssuer != "" {
jwtIssuer, err := url.Parse(c.JWTIssuer)
if err != nil || jwtIssuer.Scheme == "" || jwtIssuer.Host == "" {
return nil, errs.New("the jwt_issuer url could not be parsed")
return nil, errors.New("the jwt_issuer url could not be parsed")
Copy link
Collaborator

Choose a reason for hiding this comment

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

if that is the case, we may need to have 2 if one for err != nil and another for issuer

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.

Remove zeebo dependency
4 participants