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

Commit 688fd7f

Browse files
author
Noah Hanjun Lee
authored
Rename error codes (#228)
1 parent 1c404a0 commit 688fd7f

File tree

23 files changed

+98
-94
lines changed

23 files changed

+98
-94
lines changed

internal/interactor/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (i *Interactor) isDeployable(ctx context.Context, u *ent.User, r *ent.Repo,
183183
if ok, err := env.IsDeployableRef(d.Ref); err != nil {
184184
return false, err
185185
} else if !ok {
186-
return false, e.NewErrorWithMessage(e.ErrorCodeUnprocessableEntity, "The ref is not matched with 'deployable_ref'.", nil)
186+
return false, e.NewErrorWithMessage(e.ErrorCodeEntityUnprocessable, "The ref is not matched with 'deployable_ref'.", nil)
187187
}
188188

189189
// Check that the environment is locked.

internal/interactor/deployment_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestInteractor_Deploy(t *testing.T) {
7878
i := newMockInteractor(store, scm)
7979

8080
_, err := i.Deploy(context.Background(), &ent.User{}, &ent.Repo{}, input.d, input.e)
81-
if !e.HasErrorCode(err, e.ErrorCodeUnprocessableEntity) {
81+
if !e.HasErrorCode(err, e.ErrorCodeEntityUnprocessable) {
8282
t.Fatalf("Deploy' error = %v, wanted ErrorCodeDeploymentLocked", err)
8383
}
8484
})

internal/pkg/github/deployment.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ func (g *Github) CreateRemoteDeployment(ctx context.Context, u *ent.User, r *ent
2626
ProductionEnvironment: env.ProductionEnvironment,
2727
})
2828
if res.StatusCode == http.StatusConflict {
29-
return nil, e.NewError(
30-
e.ErrorCodeDeploymentUndeployable,
29+
return nil, e.NewErrorWithMessage(
30+
e.ErrorCodeEntityUnprocessable,
31+
"There is merge conflict or a commit status check failed.",
3132
err,
3233
)
3334
} else if res.StatusCode == http.StatusUnprocessableEntity {
@@ -76,7 +77,7 @@ func (g *Github) GetConfig(ctx context.Context, u *ent.User, r *ent.Repo) (*vo.C
7677
GetContents(ctx, r.Namespace, r.Name, r.ConfigPath, &github.RepositoryContentGetOptions{})
7778
if res.StatusCode == http.StatusNotFound {
7879
return nil, e.NewErrorWithMessage(
79-
e.ErrorCodeNotFound,
80+
e.ErrorCodeEntityNotFound,
8081
"The configuration file is not found.",
8182
err,
8283
)

internal/pkg/github/repos.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (g *Github) GetCommit(ctx context.Context, u *ent.User, r *ent.Repo, sha st
7373
GetCommit(ctx, r.Namespace, r.Name, sha)
7474
// Github returns Unprocessable entity if the commit is not found.
7575
if res.StatusCode == http.StatusNotFound || res.StatusCode == http.StatusUnprocessableEntity {
76-
return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The commit is not found.", err)
76+
return nil, e.NewErrorWithMessage(e.ErrorCodeEntityNotFound, "The commit is not found.", err)
7777
} else if err != nil {
7878
return nil, e.NewError(e.ErrorCodeInternalError, err)
7979
}
@@ -106,7 +106,7 @@ func (g *Github) ListCommitStatuses(ctx context.Context, u *ent.User, r *ent.Rep
106106
})
107107
// check-runs secures the commit is exist.
108108
if res.StatusCode == http.StatusUnprocessableEntity {
109-
return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The commit is not found.", err)
109+
return nil, e.NewErrorWithMessage(e.ErrorCodeEntityNotFound, "The commit is not found.", err)
110110
} else if err != nil {
111111
return nil, e.NewError(
112112
e.ErrorCodeInternalError,
@@ -147,7 +147,7 @@ func (g *Github) GetBranch(ctx context.Context, u *ent.User, r *ent.Repo, branch
147147
Repositories.
148148
GetBranch(ctx, r.Namespace, r.Name, branch)
149149
if res.StatusCode == http.StatusNotFound {
150-
return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The branch is not found.", err)
150+
return nil, e.NewErrorWithMessage(e.ErrorCodeEntityNotFound, "The branch is not found.", err)
151151
} else if err != nil {
152152
return nil, e.NewError(e.ErrorCodeInternalError, err)
153153
}
@@ -228,7 +228,7 @@ func (g *Github) GetTag(ctx context.Context, u *ent.User, r *ent.Repo, tag strin
228228
}
229229

230230
if q.Repository.Refs.TotalCount == 0 {
231-
return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The tag is not found.", nil)
231+
return nil, e.NewErrorWithMessage(e.ErrorCodeEntityNotFound, "The tag is not found.", nil)
232232
}
233233

234234
n := q.Repository.Refs.Nodes[0]

internal/pkg/store/deployment.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (s *Store) FindDeploymentByID(ctx context.Context, id int) (*ent.Deployment
146146
WithDeploymentStatuses().
147147
Only(ctx)
148148
if ent.IsNotFound(err) {
149-
return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The deployment is not found.", err)
149+
return nil, e.NewErrorWithMessage(e.ErrorCodeEntityNotFound, "The deployment is not found.", err)
150150
} else if err != nil {
151151
return nil, e.NewError(e.ErrorCodeInternalError, err)
152152
}
@@ -168,7 +168,7 @@ func (s *Store) FindDeploymentOfRepoByNumber(ctx context.Context, r *ent.Repo, n
168168
WithDeploymentStatuses().
169169
Only(ctx)
170170
if ent.IsNotFound(err) {
171-
return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The deployment is not found.", err)
171+
return nil, e.NewErrorWithMessage(e.ErrorCodeEntityNotFound, "The deployment is not found.", err)
172172
} else if err != nil {
173173
return nil, e.NewError(e.ErrorCodeInternalError, err)
174174
}
@@ -187,7 +187,7 @@ func (s *Store) FindDeploymentByUID(ctx context.Context, uid int64) (*ent.Deploy
187187
WithDeploymentStatuses().
188188
Only(ctx)
189189
if ent.IsNotFound(err) {
190-
return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The deployment is not found.", err)
190+
return nil, e.NewErrorWithMessage(e.ErrorCodeEntityNotFound, "The deployment is not found.", err)
191191
} else if err != nil {
192192
return nil, e.NewError(e.ErrorCodeInternalError, err)
193193
}
@@ -222,7 +222,7 @@ func (s *Store) FindPrevSuccessDeployment(ctx context.Context, d *ent.Deployment
222222
Order(ent.Desc(deployment.FieldCreatedAt)).
223223
First(ctx)
224224
if ent.IsNotFound(err) {
225-
return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The deployment is not found.", err)
225+
return nil, e.NewErrorWithMessage(e.ErrorCodeEntityNotFound, "The deployment is not found.", err)
226226
} else if err != nil {
227227
return nil, e.NewError(e.ErrorCodeInternalError, err)
228228
}
@@ -252,7 +252,7 @@ func (s *Store) CreateDeployment(ctx context.Context, d *ent.Deployment) (*ent.D
252252
return nil, e.NewError(e.ErrorCodeDeploymentConflict, err)
253253
} else if ent.IsValidationError(err) {
254254
return nil, e.NewErrorWithMessage(
255-
e.ErrorCodeUnprocessableEntity,
255+
e.ErrorCodeEntityUnprocessable,
256256
fmt.Sprintf("Failed to create a deployment. The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name),
257257
err)
258258
} else if err != nil {
@@ -281,7 +281,7 @@ func (s *Store) UpdateDeployment(ctx context.Context, d *ent.Deployment) (*ent.D
281281
Save(ctx)
282282
if ent.IsValidationError(err) {
283283
return nil, e.NewErrorWithMessage(
284-
e.ErrorCodeUnprocessableEntity,
284+
e.ErrorCodeEntityUnprocessable,
285285
fmt.Sprintf("Failed to update a deployment. The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name),
286286
err)
287287
} else if err != nil {

internal/pkg/store/deploymentstatus.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (s *Store) CreateDeploymentStatus(ctx context.Context, ds *ent.DeploymentSt
1818
Save(ctx)
1919
if ent.IsConstraintError(err) {
2020
return nil, e.NewErrorWithMessage(
21-
e.ErrorCodeUnprocessableEntity,
21+
e.ErrorCodeEntityUnprocessable,
2222
fmt.Sprintf("Failed to create a deployment status. The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name),
2323
err)
2424
} else if err != nil {
@@ -40,7 +40,7 @@ func (s *Store) SyncDeploymentStatus(ctx context.Context, ds *ent.DeploymentStat
4040
Save(ctx)
4141
if ent.IsConstraintError(err) {
4242
return nil, e.NewErrorWithMessage(
43-
e.ErrorCodeUnprocessableEntity,
43+
e.ErrorCodeEntityUnprocessable,
4444
fmt.Sprintf("Failed to sync the deployment status. The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name),
4545
err)
4646
} else if err != nil {

internal/pkg/store/lock.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (s *Store) FindLockOfRepoByEnv(ctx context.Context, r *ent.Repo, env string
4848
WithRepo().
4949
Only(ctx)
5050
if ent.IsNotFound(err) {
51-
return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The lock is not found.", err)
51+
return nil, e.NewErrorWithMessage(e.ErrorCodeEntityNotFound, "The lock is not found.", err)
5252
} else if err != nil {
5353
return nil, e.NewError(e.ErrorCodeInternalError, err)
5454
}
@@ -85,7 +85,7 @@ func (s *Store) FindLockByID(ctx context.Context, id int) (*ent.Lock, error) {
8585
WithRepo().
8686
Only(ctx)
8787
if ent.IsNotFound(err) {
88-
return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The lock is not found.", err)
88+
return nil, e.NewErrorWithMessage(e.ErrorCodeEntityNotFound, "The lock is not found.", err)
8989
} else if err != nil {
9090
return nil, e.NewError(e.ErrorCodeInternalError, err)
9191
}
@@ -103,7 +103,7 @@ func (s *Store) CreateLock(ctx context.Context, l *ent.Lock) (*ent.Lock, error)
103103
Save(ctx)
104104
if ent.IsValidationError(err) {
105105
return nil, e.NewErrorWithMessage(
106-
e.ErrorCodeUnprocessableEntity,
106+
e.ErrorCodeEntityUnprocessable,
107107
fmt.Sprintf("Failed to create a lock. The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name),
108108
err)
109109
} else if err != nil {
@@ -120,7 +120,7 @@ func (s *Store) UpdateLock(ctx context.Context, l *ent.Lock) (*ent.Lock, error)
120120
Save(ctx)
121121
if ent.IsValidationError(err) {
122122
return nil, e.NewErrorWithMessage(
123-
e.ErrorCodeUnprocessableEntity,
123+
e.ErrorCodeEntityUnprocessable,
124124
fmt.Sprintf("Failed to update the lock. The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name),
125125
err)
126126
} else if err != nil {

internal/pkg/store/perm.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (s *Store) FindPermOfRepo(ctx context.Context, r *ent.Repo, u *ent.User) (*
4646
WithUser().
4747
Only(ctx)
4848
if ent.IsNotFound(err) {
49-
return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The user has no permission for the repository.", err)
49+
return nil, e.NewErrorWithMessage(e.ErrorCodeEntityNotFound, "The user has no permission for the repository.", err)
5050
} else if err != nil {
5151
return nil, e.NewError(e.ErrorCodeInternalError, err)
5252
}
@@ -64,7 +64,7 @@ func (s *Store) CreatePerm(ctx context.Context, p *ent.Perm) (*ent.Perm, error)
6464
Save(ctx)
6565
if ent.IsValidationError(err) {
6666
return nil, e.NewErrorWithMessage(
67-
e.ErrorCodeUnprocessableEntity,
67+
e.ErrorCodeEntityUnprocessable,
6868
fmt.Sprintf("The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name),
6969
err)
7070
} else if err != nil {
@@ -82,7 +82,7 @@ func (s *Store) UpdatePerm(ctx context.Context, p *ent.Perm) (*ent.Perm, error)
8282
Save(ctx)
8383
if ent.IsValidationError(err) {
8484
return nil, e.NewErrorWithMessage(
85-
e.ErrorCodeUnprocessableEntity,
85+
e.ErrorCodeEntityUnprocessable,
8686
fmt.Sprintf("The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name),
8787
err)
8888
} else if err != nil {

internal/pkg/store/repo.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (s *Store) FindRepoByID(ctx context.Context, id int64) (*ent.Repo, error) {
104104
WithOwner().
105105
Only(ctx)
106106
if ent.IsNotFound(err) {
107-
return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The repository is not found.", err)
107+
return nil, e.NewErrorWithMessage(e.ErrorCodeEntityNotFound, "The repository is not found.", err)
108108
} else if err != nil {
109109
return nil, e.NewError(e.ErrorCodeInternalError, err)
110110
}
@@ -128,7 +128,7 @@ func (s *Store) FindRepoOfUserByID(ctx context.Context, u *ent.User, id int64) (
128128
WithOwner().
129129
Only(ctx)
130130
if ent.IsNotFound(err) {
131-
return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The repository is not found.", err)
131+
return nil, e.NewErrorWithMessage(e.ErrorCodeEntityNotFound, "The repository is not found.", err)
132132
} else if err != nil {
133133
return nil, e.NewError(e.ErrorCodeInternalError, err)
134134
}
@@ -155,7 +155,7 @@ func (s *Store) FindRepoOfUserByNamespaceName(ctx context.Context, u *ent.User,
155155
WithOwner().
156156
Only(ctx)
157157
if ent.IsNotFound(err) {
158-
return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The repository is not found.", err)
158+
return nil, e.NewErrorWithMessage(e.ErrorCodeEntityNotFound, "The repository is not found.", err)
159159
} else if err != nil {
160160
return nil, e.NewError(e.ErrorCodeInternalError, err)
161161
}
@@ -173,7 +173,7 @@ func (s *Store) SyncRepo(ctx context.Context, r *vo.RemoteRepo) (*ent.Repo, erro
173173
Save(ctx)
174174
if ent.IsValidationError(err) {
175175
return nil, e.NewErrorWithMessage(
176-
e.ErrorCodeUnprocessableEntity,
176+
e.ErrorCodeEntityUnprocessable,
177177
fmt.Sprintf("The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name),
178178
err)
179179
} else if err != nil {
@@ -190,7 +190,7 @@ func (s *Store) UpdateRepo(ctx context.Context, r *ent.Repo) (*ent.Repo, error)
190190
Save(ctx)
191191
if ent.IsValidationError(err) {
192192
return nil, e.NewErrorWithMessage(
193-
e.ErrorCodeUnprocessableEntity,
193+
e.ErrorCodeEntityUnprocessable,
194194
fmt.Sprintf("The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name),
195195
err)
196196
} else if err != nil {
@@ -209,7 +209,7 @@ func (s *Store) Activate(ctx context.Context, r *ent.Repo) (*ent.Repo, error) {
209209
Save(ctx)
210210
if ent.IsValidationError(err) {
211211
return nil, e.NewErrorWithMessage(
212-
e.ErrorCodeUnprocessableEntity,
212+
e.ErrorCodeEntityUnprocessable,
213213
fmt.Sprintf("The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name),
214214
err)
215215
} else if err != nil {
@@ -228,7 +228,7 @@ func (s *Store) Deactivate(ctx context.Context, r *ent.Repo) (*ent.Repo, error)
228228
Save(ctx)
229229
if ent.IsValidationError(err) {
230230
return nil, e.NewErrorWithMessage(
231-
e.ErrorCodeUnprocessableEntity,
231+
e.ErrorCodeEntityUnprocessable,
232232
fmt.Sprintf("The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name),
233233
err)
234234
} else if err != nil {

internal/pkg/store/review.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (s *Store) FindReviewByID(ctx context.Context, id int) (*ent.Review, error)
6161
WithDeployment().
6262
Only(ctx)
6363
if ent.IsNotFound(err) {
64-
return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The review is not found.", err)
64+
return nil, e.NewErrorWithMessage(e.ErrorCodeEntityNotFound, "The review is not found.", err)
6565
} else if err != nil {
6666
return nil, e.NewError(e.ErrorCodeInternalError, err)
6767
}
@@ -80,7 +80,7 @@ func (s *Store) FindReviewOfUser(ctx context.Context, u *ent.User, d *ent.Deploy
8080
WithDeployment().
8181
Only(ctx)
8282
if ent.IsNotFound(err) {
83-
return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The review is not found.", err)
83+
return nil, e.NewErrorWithMessage(e.ErrorCodeEntityNotFound, "The review is not found.", err)
8484
} else if err != nil {
8585
return nil, e.NewError(e.ErrorCodeInternalError, err)
8686
}
@@ -97,7 +97,7 @@ func (s *Store) CreateReview(ctx context.Context, rv *ent.Review) (*ent.Review,
9797
Save(ctx)
9898
if ent.IsValidationError(err) {
9999
return nil, e.NewErrorWithMessage(
100-
e.ErrorCodeUnprocessableEntity,
100+
e.ErrorCodeEntityUnprocessable,
101101
fmt.Sprintf("Failed to create a review. The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name),
102102
err,
103103
)
@@ -116,7 +116,7 @@ func (s *Store) UpdateReview(ctx context.Context, rv *ent.Review) (*ent.Review,
116116
Save(ctx)
117117
if ent.IsValidationError(err) {
118118
return nil, e.NewErrorWithMessage(
119-
e.ErrorCodeUnprocessableEntity,
119+
e.ErrorCodeEntityUnprocessable,
120120
fmt.Sprintf("Failed to update the review. The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name),
121121
err,
122122
)

0 commit comments

Comments
 (0)