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

Commit 1d01093

Browse files
author
Noah Lee
authored
Migrate configuration errors (#282)
* Rename the config error * Remove the config regexp error
1 parent f73efd7 commit 1d01093

File tree

4 files changed

+10
-14
lines changed

4 files changed

+10
-14
lines changed

internal/pkg/github/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (g *Github) GetConfig(ctx context.Context, u *ent.User, r *ent.Repo) (*exte
9393
c := &extent.Config{}
9494
if err := extent.UnmarshalYAML([]byte(content), c); err != nil {
9595
return nil, e.NewError(
96-
e.ErrorCodeConfigParseError,
96+
e.ErrorCodeConfigInvalid,
9797
err,
9898
)
9999
}

model/extent/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const (
6565

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

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

102102
evalued, err := envsubst.Eval(string(c.source), mapper)
103103
if err != nil {
104-
return eutil.NewError(eutil.ErrorCodeConfigParseError, err)
104+
return eutil.NewError(eutil.ErrorCodeConfigInvalid, err)
105105
}
106106

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

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

145145
matched, err := regexp.MatchString(*e.DeployableRef, ref)
146146
if err != nil {
147-
return false, eutil.NewError(eutil.ErrorCodeConfigRegexpError, err)
147+
return false, eutil.NewError(eutil.ErrorCodeConfigInvalid, err)
148148
}
149149

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

159159
matched, err := regexp.MatchString(*e.AutoDeployOn, ref)
160160
if err != nil {
161-
return false, eutil.NewError(eutil.ErrorCodeConfigRegexpError, err)
161+
return false, eutil.NewError(eutil.ErrorCodeConfigInvalid, err)
162162
}
163163

164164
return matched, nil

pkg/e/code.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ import (
66
)
77

88
const (
9-
// ErrorCodeConfigParseError is that an error occurs when it parse the file.
10-
ErrorCodeConfigParseError ErrorCode = "config_parse_error"
9+
// ErrorCodeConfigInvalid is that an error occurs when it parse the file.
10+
ErrorCodeConfigInvalid ErrorCode = "config_parse_error"
1111
// ErrorCodeConfigUndefinedEnv is that the environment is not defined in the configuration file.
1212
ErrorCodeConfigUndefinedEnv ErrorCode = "config_undefined_env"
13-
// ErrorCodeConfigRegexpError is the regexp(re2) is invalid.
14-
ErrorCodeConfigRegexpError ErrorCode = "config_regexp_error"
1513

1614
// ErrorCodeDeploymentConflict is the deployment number is conflicted.
1715
ErrorCodeDeploymentConflict ErrorCode = "deployment_conflict"

pkg/e/trans.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ package e
33
import "net/http"
44

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

3332
var httpCodes = map[ErrorCode]int{
34-
ErrorCodeConfigParseError: http.StatusUnprocessableEntity,
33+
ErrorCodeConfigInvalid: http.StatusUnprocessableEntity,
3534
ErrorCodeConfigUndefinedEnv: http.StatusUnprocessableEntity,
36-
ErrorCodeConfigRegexpError: http.StatusUnprocessableEntity,
3735
ErrorCodeDeploymentConflict: http.StatusUnprocessableEntity,
3836
ErrorCodeDeploymentInvalid: http.StatusUnprocessableEntity,
3937
ErrorCodeDeploymentLocked: http.StatusUnprocessableEntity,

0 commit comments

Comments
 (0)