Start by creating a errors.go file within the types folder. Within your errors.go file, define errors that are custom to your module along with their codes.
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
DefaultCodespace sdk.CodespaceType = ModuleName
CodeNameDoesNotExist sdk.CodeType = 101
)
Now it's time to add the corresponding method that'll be called at the time of error handling. For instance, let's say we try to delete a name that is not present in the store. In this case, an error should be thrown as the name does not exist.
func ErrNameDoesNotExist(codespace sdk.CodespaceType) sdk.Error {
return sdk.NewError(codespace, CodeNameDoesNotExist, "Name does not exist")
}
We'll see later on in the tutorial where this method is called.