diff options
author | Unknwon <u@gogs.io> | 2019-10-24 01:51:46 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-24 01:51:46 -0700 |
commit | 01c8df01ec0608f1f25b2f1444adabb98fa5ee8a (patch) | |
tree | f8a7e5dd8d2a8c51e1ce2cabb9d33571a93314dd /internal/db/errors | |
parent | 613139e7bef81d3573e7988a47eb6765f3de347a (diff) |
internal: move packages under this directory (#5836)
* Rename pkg -> internal
* Rename routes -> route
* Move route -> internal/route
* Rename models -> db
* Move db -> internal/db
* Fix route2 -> route
* Move cmd -> internal/cmd
* Bump version
Diffstat (limited to 'internal/db/errors')
-rw-r--r-- | internal/db/errors/errors.go | 14 | ||||
-rw-r--r-- | internal/db/errors/issue.go | 35 | ||||
-rw-r--r-- | internal/db/errors/login_source.go | 60 | ||||
-rw-r--r-- | internal/db/errors/org.go | 21 | ||||
-rw-r--r-- | internal/db/errors/repo.go | 87 | ||||
-rw-r--r-- | internal/db/errors/token.go | 16 | ||||
-rw-r--r-- | internal/db/errors/two_factor.go | 33 | ||||
-rw-r--r-- | internal/db/errors/user.go | 45 | ||||
-rw-r--r-- | internal/db/errors/user_mail.go | 33 | ||||
-rw-r--r-- | internal/db/errors/webhook.go | 34 |
10 files changed, 378 insertions, 0 deletions
diff --git a/internal/db/errors/errors.go b/internal/db/errors/errors.go new file mode 100644 index 00000000..cc231436 --- /dev/null +++ b/internal/db/errors/errors.go @@ -0,0 +1,14 @@ +// Copyright 2017 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package errors + +import "errors" + +var InternalServerError = errors.New("internal server error") + +// New is a wrapper of real errors.New function. +func New(text string) error { + return errors.New(text) +} diff --git a/internal/db/errors/issue.go b/internal/db/errors/issue.go new file mode 100644 index 00000000..903cc977 --- /dev/null +++ b/internal/db/errors/issue.go @@ -0,0 +1,35 @@ +// Copyright 2017 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package errors + +import "fmt" + +type IssueNotExist struct { + ID int64 + RepoID int64 + Index int64 +} + +func IsIssueNotExist(err error) bool { + _, ok := err.(IssueNotExist) + return ok +} + +func (err IssueNotExist) Error() string { + return fmt.Sprintf("issue does not exist [id: %d, repo_id: %d, index: %d]", err.ID, err.RepoID, err.Index) +} + +type InvalidIssueReference struct { + Ref string +} + +func IsInvalidIssueReference(err error) bool { + _, ok := err.(InvalidIssueReference) + return ok +} + +func (err InvalidIssueReference) Error() string { + return fmt.Sprintf("invalid issue reference [ref: %s]", err.Ref) +} diff --git a/internal/db/errors/login_source.go b/internal/db/errors/login_source.go new file mode 100644 index 00000000..dd18664e --- /dev/null +++ b/internal/db/errors/login_source.go @@ -0,0 +1,60 @@ +// Copyright 2017 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package errors + +import "fmt" + +type LoginSourceNotExist struct { + ID int64 +} + +func IsLoginSourceNotExist(err error) bool { + _, ok := err.(LoginSourceNotExist) + return ok +} + +func (err LoginSourceNotExist) Error() string { + return fmt.Sprintf("login source does not exist [id: %d]", err.ID) +} + +type LoginSourceNotActivated struct { + SourceID int64 +} + +func IsLoginSourceNotActivated(err error) bool { + _, ok := err.(LoginSourceNotActivated) + return ok +} + +func (err LoginSourceNotActivated) Error() string { + return fmt.Sprintf("login source is not activated [source_id: %d]", err.SourceID) +} + +type InvalidLoginSourceType struct { + Type interface{} +} + +func IsInvalidLoginSourceType(err error) bool { + _, ok := err.(InvalidLoginSourceType) + return ok +} + +func (err InvalidLoginSourceType) Error() string { + return fmt.Sprintf("invalid login source type [type: %v]", err.Type) +} + +type LoginSourceMismatch struct { + Expect int64 + Actual int64 +} + +func IsLoginSourceMismatch(err error) bool { + _, ok := err.(LoginSourceMismatch) + return ok +} + +func (err LoginSourceMismatch) Error() string { + return fmt.Sprintf("login source mismatch [expect: %d, actual: %d]", err.Expect, err.Actual) +} diff --git a/internal/db/errors/org.go b/internal/db/errors/org.go new file mode 100644 index 00000000..56532746 --- /dev/null +++ b/internal/db/errors/org.go @@ -0,0 +1,21 @@ +// Copyright 2018 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package errors + +import "fmt" + +type TeamNotExist struct { + TeamID int64 + Name string +} + +func IsTeamNotExist(err error) bool { + _, ok := err.(TeamNotExist) + return ok +} + +func (err TeamNotExist) Error() string { + return fmt.Sprintf("team does not exist [team_id: %d, name: %s]", err.TeamID, err.Name) +} diff --git a/internal/db/errors/repo.go b/internal/db/errors/repo.go new file mode 100644 index 00000000..c9894af9 --- /dev/null +++ b/internal/db/errors/repo.go @@ -0,0 +1,87 @@ +// Copyright 2017 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package errors + +import "fmt" + +type RepoNotExist struct { + ID int64 + UserID int64 + Name string +} + +func IsRepoNotExist(err error) bool { + _, ok := err.(RepoNotExist) + return ok +} + +func (err RepoNotExist) Error() string { + return fmt.Sprintf("repository does not exist [id: %d, user_id: %d, name: %s]", err.ID, err.UserID, err.Name) +} + +type ReachLimitOfRepo struct { + Limit int +} + +func IsReachLimitOfRepo(err error) bool { + _, ok := err.(ReachLimitOfRepo) + return ok +} + +func (err ReachLimitOfRepo) Error() string { + return fmt.Sprintf("user has reached maximum limit of repositories [limit: %d]", err.Limit) +} + +type InvalidRepoReference struct { + Ref string +} + +func IsInvalidRepoReference(err error) bool { + _, ok := err.(InvalidRepoReference) + return ok +} + +func (err InvalidRepoReference) Error() string { + return fmt.Sprintf("invalid repository reference [ref: %s]", err.Ref) +} + +type MirrorNotExist struct { + RepoID int64 +} + +func IsMirrorNotExist(err error) bool { + _, ok := err.(MirrorNotExist) + return ok +} + +func (err MirrorNotExist) Error() string { + return fmt.Sprintf("mirror does not exist [repo_id: %d]", err.RepoID) +} + +type BranchAlreadyExists struct { + Name string +} + +func IsBranchAlreadyExists(err error) bool { + _, ok := err.(BranchAlreadyExists) + return ok +} + +func (err BranchAlreadyExists) Error() string { + return fmt.Sprintf("branch already exists [name: %s]", err.Name) +} + +type ErrBranchNotExist struct { + Name string +} + +func IsErrBranchNotExist(err error) bool { + _, ok := err.(ErrBranchNotExist) + return ok +} + +func (err ErrBranchNotExist) Error() string { + return fmt.Sprintf("branch does not exist [name: %s]", err.Name) +} diff --git a/internal/db/errors/token.go b/internal/db/errors/token.go new file mode 100644 index 00000000..d6a4577a --- /dev/null +++ b/internal/db/errors/token.go @@ -0,0 +1,16 @@ +package errors + +import "fmt" + +type AccessTokenNameAlreadyExist struct { + Name string +} + +func IsAccessTokenNameAlreadyExist(err error) bool { + _, ok := err.(AccessTokenNameAlreadyExist) + return ok +} + +func (err AccessTokenNameAlreadyExist) Error() string { + return fmt.Sprintf("access token already exist [name: %s]", err.Name) +} diff --git a/internal/db/errors/two_factor.go b/internal/db/errors/two_factor.go new file mode 100644 index 00000000..02cdcf5c --- /dev/null +++ b/internal/db/errors/two_factor.go @@ -0,0 +1,33 @@ +// Copyright 2017 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package errors + +import "fmt" + +type TwoFactorNotFound struct { + UserID int64 +} + +func IsTwoFactorNotFound(err error) bool { + _, ok := err.(TwoFactorNotFound) + return ok +} + +func (err TwoFactorNotFound) Error() string { + return fmt.Sprintf("two-factor authentication does not found [user_id: %d]", err.UserID) +} + +type TwoFactorRecoveryCodeNotFound struct { + Code string +} + +func IsTwoFactorRecoveryCodeNotFound(err error) bool { + _, ok := err.(TwoFactorRecoveryCodeNotFound) + return ok +} + +func (err TwoFactorRecoveryCodeNotFound) Error() string { + return fmt.Sprintf("two-factor recovery code does not found [code: %s]", err.Code) +} diff --git a/internal/db/errors/user.go b/internal/db/errors/user.go new file mode 100644 index 00000000..526d4b2d --- /dev/null +++ b/internal/db/errors/user.go @@ -0,0 +1,45 @@ +// Copyright 2017 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package errors + +import "fmt" + +type EmptyName struct{} + +func IsEmptyName(err error) bool { + _, ok := err.(EmptyName) + return ok +} + +func (err EmptyName) Error() string { + return "empty name" +} + +type UserNotExist struct { + UserID int64 + Name string +} + +func IsUserNotExist(err error) bool { + _, ok := err.(UserNotExist) + return ok +} + +func (err UserNotExist) Error() string { + return fmt.Sprintf("user does not exist [user_id: %d, name: %s]", err.UserID, err.Name) +} + +type UserNotKeyOwner struct { + KeyID int64 +} + +func IsUserNotKeyOwner(err error) bool { + _, ok := err.(UserNotKeyOwner) + return ok +} + +func (err UserNotKeyOwner) Error() string { + return fmt.Sprintf("user is not the owner of public key [key_id: %d]", err.KeyID) +} diff --git a/internal/db/errors/user_mail.go b/internal/db/errors/user_mail.go new file mode 100644 index 00000000..fcdeb78c --- /dev/null +++ b/internal/db/errors/user_mail.go @@ -0,0 +1,33 @@ +// Copyright 2017 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package errors + +import "fmt" + +type EmailNotFound struct { + Email string +} + +func IsEmailNotFound(err error) bool { + _, ok := err.(EmailNotFound) + return ok +} + +func (err EmailNotFound) Error() string { + return fmt.Sprintf("email is not found [email: %s]", err.Email) +} + +type EmailNotVerified struct { + Email string +} + +func IsEmailNotVerified(err error) bool { + _, ok := err.(EmailNotVerified) + return ok +} + +func (err EmailNotVerified) Error() string { + return fmt.Sprintf("email has not been verified [email: %s]", err.Email) +} diff --git a/internal/db/errors/webhook.go b/internal/db/errors/webhook.go new file mode 100644 index 00000000..76cf8cb4 --- /dev/null +++ b/internal/db/errors/webhook.go @@ -0,0 +1,34 @@ +// Copyright 2017 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package errors + +import "fmt" + +type WebhookNotExist struct { + ID int64 +} + +func IsWebhookNotExist(err error) bool { + _, ok := err.(WebhookNotExist) + return ok +} + +func (err WebhookNotExist) Error() string { + return fmt.Sprintf("webhook does not exist [id: %d]", err.ID) +} + +type HookTaskNotExist struct { + HookID int64 + UUID string +} + +func IsHookTaskNotExist(err error) bool { + _, ok := err.(HookTaskNotExist) + return ok +} + +func (err HookTaskNotExist) Error() string { + return fmt.Sprintf("hook task does not exist [hook_id: %d, uuid: %s]", err.HookID, err.UUID) +} |