At Mattermost, we are committed to maintaining a high standard of code quality, reliability, and security. To further enhance this, we are launching a community campaign to integrate the errcheck linter across the Mattermost codebase.
This Help Wanted ticket is about fixing the linter issues reported by errcheck in channels/api4/emoji.go.
What is errcheck?
errcheck is a tool that automatically identifies places in Go code where errors are returned but not checked. In Go, error handling is a critical part of writing robust applications, and ignoring returned errors can lead to bugs, crashes, or unintended behaviour. By integrating errcheck into the codebase, we can ensure that error handling is consistently and properly managed across the project.
Tasks
Remove the exception for channels/api4/emoji.go from the exceptions list for errcheck in server/.golangci.yml.
Run make golangci-lint to get a list of all linter errors.
Fix the errors by properly handling them.
Run make golangci-lint again to ensure all errors are fixed.
Okay, but what does "properly handling" mean?
In general, errors should be returned to the caller. Non critical errors should be loggged, and function execution should continue. There are some exceptions to this rule, such as when the error is expected and should be ignored or when the error is handled in a different way. In such cases, a comment should be added to explain why the error is ignored.
In tests, errors should be checked using require.NoError(t, err) for errors of type error or require.Nil(t, err) for errors of type **model.AppError.
If an error is expected, it should be checked using require.Error(t, err) for errors of type error or require.NotNil(t, err) for errors of type **model.AppError.
Use err as the variable name for errors and appErr for *model.AppError. Avoid using variable names like err1, err2, etc. See the Mattermost style guide for more information.
At Mattermost, we are committed to maintaining a high standard of code quality, reliability, and security. To further enhance this, we are launching a community campaign to integrate the
errcheck
linter across the Mattermost codebase.This Help Wanted ticket is about fixing the linter issues reported by
errcheck
inchannels/api4/emoji.go
.What is
errcheck
?errcheck
is a tool that automatically identifies places in Go code where errors are returned but not checked. In Go, error handling is a critical part of writing robust applications, and ignoring returned errors can lead to bugs, crashes, or unintended behaviour. By integratingerrcheck
into the codebase, we can ensure that error handling is consistently and properly managed across the project.Tasks
channels/api4/emoji.go
from the exceptions list forerrcheck
inserver/.golangci.yml
.make golangci-lint
to get a list of all linter errors.make golangci-lint
again to ensure all errors are fixed.Okay, but what does "properly handling" mean?
In general, errors should be returned to the caller. Non critical errors should be loggged, and function execution should continue. There are some exceptions to this rule, such as when the error is expected and should be ignored or when the error is handled in a different way. In such cases, a comment should be added to explain why the error is ignored.
In tests, errors should be checked using
require.NoError(t, err)
for errors of typeerror
orrequire.Nil(t, err)
for errors of type**model.AppError
. If an error is expected, it should be checked usingrequire.Error(t, err)
for errors of typeerror
orrequire.NotNil(t, err)
for errors of type**model.AppError
.Use
err
as the variable name for errors andappErr
for*model.AppError
. Avoid using variable names likeerr1
,err2
, etc. See the Mattermost style guide for more information.https://github.com/mattermost/mattermost/pull/28364 and https://github.com/mattermost/mattermost/pull/28376 can be used as examples of how to fix
errcheck
issues in theapi4
package.If you're interested, please comment here and come join our "Contributors" community channel on the Mattermost Community server, where you can discuss questions with community members and the Mattermost core team. For technical advice or questions, please join our "Developers Server" community channel. You can also reach out to @hanzei either on this ticket or on the Mattermost Community server.
For new contributors, please see our Developer's Guide.
JIRA: MM-60748