Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Migrate configuration errors #282

Merged
merged 2 commits into from
Dec 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/pkg/github/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (g *Github) GetConfig(ctx context.Context, u *ent.User, r *ent.Repo) (*exte
c := &extent.Config{}
if err := extent.UnmarshalYAML([]byte(content), c); err != nil {
return nil, e.NewError(
e.ErrorCodeConfigParseError,
e.ErrorCodeConfigInvalid,
err,
)
}
Expand Down
10 changes: 5 additions & 5 deletions model/extent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const (

func UnmarshalYAML(content []byte, c *Config) error {
if err := yaml.Unmarshal([]byte(content), c); err != nil {
return eutil.NewError(eutil.ErrorCodeConfigParseError, err)
return eutil.NewError(eutil.ErrorCodeConfigInvalid, err)
}

c.source = content
Expand Down Expand Up @@ -101,11 +101,11 @@ func (c *Config) Eval(v *EvalValues) error {

evalued, err := envsubst.Eval(string(c.source), mapper)
if err != nil {
return eutil.NewError(eutil.ErrorCodeConfigParseError, err)
return eutil.NewError(eutil.ErrorCodeConfigInvalid, err)
}

if err := yaml.Unmarshal([]byte(evalued), c); err != nil {
return eutil.NewError(eutil.ErrorCodeConfigParseError, err)
return eutil.NewError(eutil.ErrorCodeConfigInvalid, err)
}

return nil
Expand Down Expand Up @@ -144,7 +144,7 @@ func (e *Env) IsDeployableRef(ref string) (bool, error) {

matched, err := regexp.MatchString(*e.DeployableRef, ref)
if err != nil {
return false, eutil.NewError(eutil.ErrorCodeConfigRegexpError, err)
return false, eutil.NewError(eutil.ErrorCodeConfigInvalid, err)
}

return matched, nil
Expand All @@ -158,7 +158,7 @@ func (e *Env) IsAutoDeployOn(ref string) (bool, error) {

matched, err := regexp.MatchString(*e.AutoDeployOn, ref)
if err != nil {
return false, eutil.NewError(eutil.ErrorCodeConfigRegexpError, err)
return false, eutil.NewError(eutil.ErrorCodeConfigInvalid, err)
}

return matched, nil
Expand Down
6 changes: 2 additions & 4 deletions pkg/e/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import (
)

const (
// ErrorCodeConfigParseError is that an error occurs when it parse the file.
ErrorCodeConfigParseError ErrorCode = "config_parse_error"
// ErrorCodeConfigInvalid is that an error occurs when it parse the file.
ErrorCodeConfigInvalid ErrorCode = "config_parse_error"
// ErrorCodeConfigUndefinedEnv is that the environment is not defined in the configuration file.
ErrorCodeConfigUndefinedEnv ErrorCode = "config_undefined_env"
// ErrorCodeConfigRegexpError is the regexp(re2) is invalid.
ErrorCodeConfigRegexpError ErrorCode = "config_regexp_error"

// ErrorCodeDeploymentConflict is the deployment number is conflicted.
ErrorCodeDeploymentConflict ErrorCode = "deployment_conflict"
Expand Down
6 changes: 2 additions & 4 deletions pkg/e/trans.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package e
import "net/http"

var messages = map[ErrorCode]string{
ErrorCodeConfigParseError: "The configuration is invalid.",
ErrorCodeConfigInvalid: "The configuration is invalid.",
ErrorCodeConfigUndefinedEnv: "The environment is not defined in the configuration.",
ErrorCodeConfigRegexpError: "The regexp is invalid.",
ErrorCodeDeploymentConflict: "The conflict occurs, please retry.",
ErrorCodeDeploymentInvalid: "The validation has failed.",
ErrorCodeDeploymentLocked: "The environment is locked.",
Expand All @@ -31,9 +30,8 @@ func GetMessage(code ErrorCode) string {
}

var httpCodes = map[ErrorCode]int{
ErrorCodeConfigParseError: http.StatusUnprocessableEntity,
ErrorCodeConfigInvalid: http.StatusUnprocessableEntity,
ErrorCodeConfigUndefinedEnv: http.StatusUnprocessableEntity,
ErrorCodeConfigRegexpError: http.StatusUnprocessableEntity,
ErrorCodeDeploymentConflict: http.StatusUnprocessableEntity,
ErrorCodeDeploymentInvalid: http.StatusUnprocessableEntity,
ErrorCodeDeploymentLocked: http.StatusUnprocessableEntity,
Expand Down