-
Notifications
You must be signed in to change notification settings - Fork 18k
vet: fmt.Errorf("ordinary string") should be replaced by errors.New("ordinary string") #17173
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
Comments
I'm not sure this is worth a vet check.
For packages that already imports fmt, there is nothing to gain
from using errors.New instead of fmt.Errorf (except slight
performance gain, but that shouldn't matter).
benchmark: https://play.golang.org/p/gXzQC2Ux4J
|
I'm going to close this, but feel free to open the issue on the |
For the reason I've given, I don't even think it's appropriate for golint
to complain about: it's not a mistake if the package is already using
the fmt package.
|
Perhaps you could try https://github.com/dominikh/go-simple |
It's probably not appropriate for gosimple, either, for the reason minux has given. One could of course check if fmt is being used for anything else already, but I don't think the slight benefit is worth the added complexity. |
Well thought I'd mention it as it was the most likely place it would find a home that I know of. Personally I'd consider it a simplification even if it meant importing errors and fmt. A Printf/Errorf/Anythingf with just a string looks wrong. Understandable if it's out of scope, though. |
OK |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.7.1
What operating system and processor architecture are you using (
go env
)?All
What did you do?
Vet this program: https://play.golang.org/p/krp8cxL_Lv
What did you expect to see?
fmt.Errorf("an ordinary string")
- with no formatting arguments - should be replaced byerrors.New("an ordinary string")
, to avoid the overhead of callingerrors.New(Sprintf(...))
.What did you see instead?
No warning.
I'm happy to try to provide a patch here, if this is of interest.
The text was updated successfully, but these errors were encountered: