Mattermost is migrating all usages of the AppError type to the more idiomatic error type. AppError is a loaded error type containing fields like HTTP Status code which is not really necessary for errors coming from the DB layer. We should migrate to using normal types satisfying the error interface.
This ticket is about migrating all usages of AppError from store/sqlstore/command*webhook*store.go to return a normal error. The migration should use the error types defined in store/errors.go. If the need should arise to add another specific error type, feel free to add it. For any generic error that is not something like an invalid input, or something not found, we can just wrap the error using errors.Wrap(f) and return it.
And then in the app layer, we would need to convert the error type to the usual AppError. Essentially moving the AppError creation from the store layer to the app layer. This means we need a switch case to check for the type of error and appropriately convert to the correct AppError. It can be something like:
if _, err := a.Srv().Store.Bot().Update(bot); err != nil {
var nfErr *store.ErrNotFound
var appErr *model.AppError
switch {
case errors.As(err, &nfErr):
return model.MakeBotNotFoundError(nfErr.Id)
case errors.As(err, &appErr): // in case we haven't converted to plain error.
return appErr
default: // last fallback in case it doesn't map to an existing app error.
return model.NewAppError("DeleteBotIconImage", "app.bot.patchbot.internal_error", nil, err.Error(), http.StatusInternalServerError)
}
}
Also note that the error codes need to be changed from being a store level code (store.<>.edit.error) to something like app.<>.edit.internal_error.
Example Pull Request: #14339
If you have questions about the ticket or you need any help, feel free to contact agniva.de.sarker in https://community.mattermost.com/
If you're interested please comment here and come join our "Contributors" community channel on our daily build server, where you can discuss questions with community members and the Mattermost core team. For technical advice or questions, please join our "Developers" community channel.
New contributors please see our Developer's Guide.
Please assign me this one.
Most helpful comment
Please assign me this one.