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

Improve global error detection #32

Merged

Conversation

leonklingele
Copy link
Contributor

@leonklingele leonklingele commented Feb 13, 2022

Only treat global error variables as such if they have an "err" or "Err" prefix
and implement the error interface.

Close #5

Only treat global error variables as such if they have an "err" or "Err" prefix
and implement the error interface.

Implements leighmcculloch#5.
@leonklingele leonklingele force-pushed the improve-error-detection branch from d5bf92f to 0eb5c38 Compare February 13, 2022 18:07
@hurrycaner
Copy link

I would like to suggest making that prefix configurable, i would like to use the error interface implementation feature, but not that err or Err prefixes

@leighmcculloch
Copy link
Owner

leighmcculloch commented Sep 17, 2022

This looks good to me, but I'm a little concerned with the fact that this is a breaking change potentially as it reduces the surface area of what is allowed. It's okay for us to increase the surface area of what is allowed but reducing it may break existing builds.

Maybe that's okay. Or maybe this gets released in a new major version. Does anyone else have thoughts on this?

@leighmcculloch
Copy link
Owner

@hurrycaner the idea to use the err prefix for non error globals sounds out of scope of this tool.

@leonklingele
Copy link
Contributor Author

Hey @leighmcculloch, can this be merged? 😊

Copy link
Owner

@leighmcculloch leighmcculloch left a comment

Choose a reason for hiding this comment

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

This looks good to me. There's one test case I'd like to add, to make sure we don't have a gap there. See below.

Comment on lines 93 to 101
prefix := "err"
if i.IsExported() {
prefix = "Err"
}
return strings.HasPrefix(i.Name, prefix)

hasErrPrefix := strings.HasPrefix(i.Name, prefix)
if !hasErrPrefix {
return false
}
Copy link
Owner

Choose a reason for hiding this comment

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

@leonklingele @bombsimon Do you folks have thoughts on if we should remove the err/Err prefix requirement? Regardless of the name given to the global variable, just checking if it is an error seems reasonable to me.

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'd leave it as-is. We could make it configurable with a default that still enforces the prefix but I don't really see a benefit in doing so.

@leighmcculloch leighmcculloch merged commit 03b61a6 into leighmcculloch:master Jan 16, 2023
@leighmcculloch
Copy link
Owner

Release in v0.2.0.

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.

Improve global error variable detection
3 participants