summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/asymkey/ssh_key_fingerprint.go5
-rw-r--r--models/asymkey/ssh_key_parse.go5
-rw-r--r--models/asymkey/ssh_key_principals.go4
-rw-r--r--models/org_team.go5
-rw-r--r--models/packages/conan/references.go6
-rw-r--r--models/packages/container/search.go4
-rw-r--r--models/packages/package.go6
-rw-r--r--models/packages/package_blob.go4
-rw-r--r--models/packages/package_blob_upload.go3
-rw-r--r--models/packages/package_cleanup_rule.go4
-rw-r--r--models/packages/package_file.go6
-rw-r--r--models/packages/package_version.go3
-rw-r--r--models/project/project.go3
-rw-r--r--models/repo/mirror.go4
-rw-r--r--models/repo/pushmirror.go6
-rw-r--r--models/repo/release.go3
-rw-r--r--models/repo/repo_list.go3
-rw-r--r--models/unittest/fscopy.go2
-rw-r--r--models/user/email_address.go3
-rw-r--r--models/user/openid.go3
20 files changed, 36 insertions, 46 deletions
diff --git a/models/asymkey/ssh_key_fingerprint.go b/models/asymkey/ssh_key_fingerprint.go
index ca0334cc0b..8a8d4fce15 100644
--- a/models/asymkey/ssh_key_fingerprint.go
+++ b/models/asymkey/ssh_key_fingerprint.go
@@ -5,7 +5,6 @@ package asymkey
import (
"context"
- "errors"
"fmt"
"strings"
@@ -59,9 +58,9 @@ func calcFingerprintSSHKeygen(publicKeyContent string) (string, error) {
if strings.Contains(stderr, "is not a public key file") {
return "", ErrKeyUnableVerify{stderr}
}
- return "", fmt.Errorf("'ssh-keygen -lf %s' failed with error '%s': %s", tmpPath, err, stderr)
+ return "", util.NewInvalidArgumentErrorf("'ssh-keygen -lf %s' failed with error '%s': %s", tmpPath, err, stderr)
} else if len(stdout) < 2 {
- return "", errors.New("not enough output for calculating fingerprint: " + stdout)
+ return "", util.NewInvalidArgumentErrorf("not enough output for calculating fingerprint: %s", stdout)
}
return strings.Split(stdout, " ")[1], nil
}
diff --git a/models/asymkey/ssh_key_parse.go b/models/asymkey/ssh_key_parse.go
index b3eecb2c9b..1df6db6fa7 100644
--- a/models/asymkey/ssh_key_parse.go
+++ b/models/asymkey/ssh_key_parse.go
@@ -10,7 +10,6 @@ import (
"encoding/base64"
"encoding/binary"
"encoding/pem"
- "errors"
"fmt"
"math/big"
"os"
@@ -122,7 +121,7 @@ func parseKeyString(content string) (string, error) {
parts := strings.SplitN(content, " ", 3)
switch len(parts) {
case 0:
- return "", errors.New("empty key")
+ return "", util.NewInvalidArgumentErrorf("empty key")
case 1:
keyContent = parts[0]
case 2:
@@ -167,7 +166,7 @@ func CheckPublicKeyString(content string) (_ string, err error) {
content = strings.TrimRight(content, "\n\r")
if strings.ContainsAny(content, "\n\r") {
- return "", errors.New("only a single line with a single key please")
+ return "", util.NewInvalidArgumentErrorf("only a single line with a single key please")
}
// remove any unnecessary whitespace now
diff --git a/models/asymkey/ssh_key_principals.go b/models/asymkey/ssh_key_principals.go
index f00c3f3e9e..6d43437ec1 100644
--- a/models/asymkey/ssh_key_principals.go
+++ b/models/asymkey/ssh_key_principals.go
@@ -4,7 +4,6 @@
package asymkey
import (
- "errors"
"fmt"
"strings"
@@ -12,6 +11,7 @@ import (
"code.gitea.io/gitea/models/perm"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/util"
)
// __________ .__ .__ .__
@@ -70,7 +70,7 @@ func CheckPrincipalKeyString(user *user_model.User, content string) (_ string, e
content = strings.TrimSpace(content)
if strings.ContainsAny(content, "\r\n") {
- return "", errors.New("only a single line with a single principal please")
+ return "", util.NewInvalidArgumentErrorf("only a single line with a single principal please")
}
// check all the allowed principals, email, username or anything
diff --git a/models/org_team.go b/models/org_team.go
index a5a2575eec..b3ee842c1f 100644
--- a/models/org_team.go
+++ b/models/org_team.go
@@ -6,7 +6,6 @@ package models
import (
"context"
- "errors"
"fmt"
"strings"
@@ -235,7 +234,7 @@ func RemoveRepository(t *organization.Team, repoID int64) error {
// It's caller's responsibility to assign organization ID.
func NewTeam(t *organization.Team) (err error) {
if len(t.Name) == 0 {
- return errors.New("empty team name")
+ return util.NewInvalidArgumentErrorf("empty team name")
}
if err = organization.IsUsableTeamName(t.Name); err != nil {
@@ -300,7 +299,7 @@ func NewTeam(t *organization.Team) (err error) {
// UpdateTeam updates information of team.
func UpdateTeam(t *organization.Team, authChanged, includeAllChanged bool) (err error) {
if len(t.Name) == 0 {
- return errors.New("empty team name")
+ return util.NewInvalidArgumentErrorf("empty team name")
}
if len(t.Description) > 255 {
diff --git a/models/packages/conan/references.go b/models/packages/conan/references.go
index 06e828e8fa..0d888a1ec8 100644
--- a/models/packages/conan/references.go
+++ b/models/packages/conan/references.go
@@ -5,7 +5,6 @@ package conan
import (
"context"
- "errors"
"strconv"
"strings"
@@ -13,13 +12,14 @@ import (
"code.gitea.io/gitea/models/packages"
conan_module "code.gitea.io/gitea/modules/packages/conan"
"code.gitea.io/gitea/modules/timeutil"
+ "code.gitea.io/gitea/modules/util"
"xorm.io/builder"
)
var (
- ErrRecipeReferenceNotExist = errors.New("Recipe reference does not exist")
- ErrPackageReferenceNotExist = errors.New("Package reference does not exist")
+ ErrRecipeReferenceNotExist = util.NewNotExistErrorf("recipe reference does not exist")
+ ErrPackageReferenceNotExist = util.NewNotExistErrorf("package reference does not exist")
)
// RecipeExists checks if a recipe exists
diff --git a/models/packages/container/search.go b/models/packages/container/search.go
index dfd5e244ba..2e35c44766 100644
--- a/models/packages/container/search.go
+++ b/models/packages/container/search.go
@@ -5,7 +5,6 @@ package container
import (
"context"
- "errors"
"strings"
"time"
@@ -13,11 +12,12 @@ import (
"code.gitea.io/gitea/models/packages"
user_model "code.gitea.io/gitea/models/user"
container_module "code.gitea.io/gitea/modules/packages/container"
+ "code.gitea.io/gitea/modules/util"
"xorm.io/builder"
)
-var ErrContainerBlobNotExist = errors.New("Container blob does not exist")
+var ErrContainerBlobNotExist = util.NewNotExistErrorf("container blob does not exist")
type BlobSearchOptions struct {
OwnerID int64
diff --git a/models/packages/package.go b/models/packages/package.go
index 5c4837d98b..a804f35de3 100644
--- a/models/packages/package.go
+++ b/models/packages/package.go
@@ -5,11 +5,11 @@ package packages
import (
"context"
- "errors"
"fmt"
"strings"
"code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/modules/util"
"xorm.io/builder"
)
@@ -20,9 +20,9 @@ func init() {
var (
// ErrDuplicatePackage indicates a duplicated package error
- ErrDuplicatePackage = errors.New("Package does exist already")
+ ErrDuplicatePackage = util.NewAlreadyExistErrorf("package already exists")
// ErrPackageNotExist indicates a package not exist error
- ErrPackageNotExist = errors.New("Package does not exist")
+ ErrPackageNotExist = util.NewNotExistErrorf("package does not exist")
)
// Type of a package
diff --git a/models/packages/package_blob.go b/models/packages/package_blob.go
index 36ad745312..3b4a1ecf18 100644
--- a/models/packages/package_blob.go
+++ b/models/packages/package_blob.go
@@ -5,15 +5,15 @@ package packages
import (
"context"
- "errors"
"time"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/timeutil"
+ "code.gitea.io/gitea/modules/util"
)
// ErrPackageBlobNotExist indicates a package blob not exist error
-var ErrPackageBlobNotExist = errors.New("Package blob does not exist")
+var ErrPackageBlobNotExist = util.NewNotExistErrorf("package blob does not exist")
func init() {
db.RegisterModel(new(PackageBlob))
diff --git a/models/packages/package_blob_upload.go b/models/packages/package_blob_upload.go
index 64d1f9d473..4b0e789221 100644
--- a/models/packages/package_blob_upload.go
+++ b/models/packages/package_blob_upload.go
@@ -5,7 +5,6 @@ package packages
import (
"context"
- "errors"
"strings"
"time"
@@ -15,7 +14,7 @@ import (
)
// ErrPackageBlobUploadNotExist indicates a package blob upload not exist error
-var ErrPackageBlobUploadNotExist = errors.New("Package blob upload does not exist")
+var ErrPackageBlobUploadNotExist = util.NewNotExistErrorf("package blob upload does not exist")
func init() {
db.RegisterModel(new(PackageBlobUpload))
diff --git a/models/packages/package_cleanup_rule.go b/models/packages/package_cleanup_rule.go
index 9bd512755d..fa12dec406 100644
--- a/models/packages/package_cleanup_rule.go
+++ b/models/packages/package_cleanup_rule.go
@@ -5,17 +5,17 @@ package packages
import (
"context"
- "errors"
"fmt"
"regexp"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/timeutil"
+ "code.gitea.io/gitea/modules/util"
"xorm.io/builder"
)
-var ErrPackageCleanupRuleNotExist = errors.New("Package blob does not exist")
+var ErrPackageCleanupRuleNotExist = util.NewNotExistErrorf("package blob does not exist")
func init() {
db.RegisterModel(new(PackageCleanupRule))
diff --git a/models/packages/package_file.go b/models/packages/package_file.go
index 6d0fd185a0..7f794836dc 100644
--- a/models/packages/package_file.go
+++ b/models/packages/package_file.go
@@ -5,13 +5,13 @@ package packages
import (
"context"
- "errors"
"strconv"
"strings"
"time"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/timeutil"
+ "code.gitea.io/gitea/modules/util"
"xorm.io/builder"
)
@@ -22,9 +22,9 @@ func init() {
var (
// ErrDuplicatePackageFile indicates a duplicated package file error
- ErrDuplicatePackageFile = errors.New("Package file does exist already")
+ ErrDuplicatePackageFile = util.NewAlreadyExistErrorf("package file already exists")
// ErrPackageFileNotExist indicates a package file not exist error
- ErrPackageFileNotExist = errors.New("Package file does not exist")
+ ErrPackageFileNotExist = util.NewNotExistErrorf("package file does not exist")
)
// EmptyFileKey is a named constant for an empty file key
diff --git a/models/packages/package_version.go b/models/packages/package_version.go
index 928f9d47d6..759c20abed 100644
--- a/models/packages/package_version.go
+++ b/models/packages/package_version.go
@@ -5,7 +5,6 @@ package packages
import (
"context"
- "errors"
"strconv"
"strings"
@@ -17,7 +16,7 @@ import (
)
// ErrDuplicatePackageVersion indicates a duplicated package version error
-var ErrDuplicatePackageVersion = errors.New("Package version already exists")
+var ErrDuplicatePackageVersion = util.NewAlreadyExistErrorf("package version already exists")
func init() {
db.RegisterModel(new(PackageVersion))
diff --git a/models/project/project.go b/models/project/project.go
index bcf1166408..0a07cfe22a 100644
--- a/models/project/project.go
+++ b/models/project/project.go
@@ -5,7 +5,6 @@ package project
import (
"context"
- "errors"
"fmt"
"code.gitea.io/gitea/models/db"
@@ -176,7 +175,7 @@ func NewProject(p *Project) error {
}
if !IsTypeValid(p.Type) {
- return errors.New("project type is not valid")
+ return util.NewInvalidArgumentErrorf("project type is not valid")
}
ctx, committer, err := db.TxContext(db.DefaultContext)
diff --git a/models/repo/mirror.go b/models/repo/mirror.go
index 2f59b85331..c1d24a4886 100644
--- a/models/repo/mirror.go
+++ b/models/repo/mirror.go
@@ -6,16 +6,16 @@ package repo
import (
"context"
- "errors"
"time"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/timeutil"
+ "code.gitea.io/gitea/modules/util"
)
// ErrMirrorNotExist mirror does not exist error
-var ErrMirrorNotExist = errors.New("Mirror does not exist")
+var ErrMirrorNotExist = util.NewNotExistErrorf("Mirror does not exist")
// Mirror represents mirror information of a repository.
type Mirror struct {
diff --git a/models/repo/pushmirror.go b/models/repo/pushmirror.go
index f79ce59ee2..642020bb5e 100644
--- a/models/repo/pushmirror.go
+++ b/models/repo/pushmirror.go
@@ -5,18 +5,18 @@ package repo
import (
"context"
- "errors"
"time"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/timeutil"
+ "code.gitea.io/gitea/modules/util"
"xorm.io/builder"
)
// ErrPushMirrorNotExist mirror does not exist error
-var ErrPushMirrorNotExist = errors.New("PushMirror does not exist")
+var ErrPushMirrorNotExist = util.NewNotExistErrorf("PushMirror does not exist")
// PushMirror represents mirror information of a repository.
type PushMirror struct {
@@ -90,7 +90,7 @@ func DeletePushMirrors(ctx context.Context, opts PushMirrorOptions) error {
_, err := db.GetEngine(ctx).Where(opts.toConds()).Delete(&PushMirror{})
return err
}
- return errors.New("repoID required and must be set")
+ return util.NewInvalidArgumentErrorf("repoID required and must be set")
}
func GetPushMirror(ctx context.Context, opts PushMirrorOptions) (*PushMirror, error) {
diff --git a/models/repo/release.go b/models/repo/release.go
index 25eba10e05..08b429f5e1 100644
--- a/models/repo/release.go
+++ b/models/repo/release.go
@@ -6,7 +6,6 @@ package repo
import (
"context"
- "errors"
"fmt"
"sort"
"strconv"
@@ -156,7 +155,7 @@ func AddReleaseAttachments(ctx context.Context, releaseID int64, attachmentUUIDs
for i := range attachments {
if attachments[i].ReleaseID != 0 {
- return errors.New("release permission denied")
+ return util.NewPermissionDeniedErrorf("release permission denied")
}
attachments[i].ReleaseID = releaseID
// No assign value could be 0, so ignore AllCols().
diff --git a/models/repo/repo_list.go b/models/repo/repo_list.go
index 6d9dd9ec65..9922ff25a2 100644
--- a/models/repo/repo_list.go
+++ b/models/repo/repo_list.go
@@ -5,7 +5,6 @@ package repo
import (
"context"
- "errors"
"fmt"
"strings"
@@ -708,7 +707,7 @@ func GetUserRepositories(opts *SearchRepoOptions) (RepositoryList, int64, error)
cond := builder.NewCond()
if opts.Actor == nil {
- return nil, 0, errors.New("GetUserRepositories: Actor is needed but not given")
+ return nil, 0, util.NewInvalidArgumentErrorf("GetUserRepositories: Actor is needed but not given")
}
cond = cond.And(builder.Eq{"owner_id": opts.Actor.ID})
if !opts.Private {
diff --git a/models/unittest/fscopy.go b/models/unittest/fscopy.go
index 631da49f2d..74b12d5057 100644
--- a/models/unittest/fscopy.go
+++ b/models/unittest/fscopy.go
@@ -64,7 +64,7 @@ func Copy(src, dest string) error {
func CopyDir(srcPath, destPath string, filters ...func(filePath string) bool) error {
// Check if target directory exists.
if _, err := os.Stat(destPath); !errors.Is(err, os.ErrNotExist) {
- return errors.New("file or directory already exists: " + destPath)
+ return util.NewAlreadyExistErrorf("file or directory already exists: %s", destPath)
}
err := os.MkdirAll(destPath, os.ModePerm)
diff --git a/models/user/email_address.go b/models/user/email_address.go
index 69e94f8bb6..e310858f92 100644
--- a/models/user/email_address.go
+++ b/models/user/email_address.go
@@ -6,7 +6,6 @@ package user
import (
"context"
- "errors"
"fmt"
"net/mail"
"regexp"
@@ -22,7 +21,7 @@ import (
)
// ErrEmailNotActivated e-mail address has not been activated error
-var ErrEmailNotActivated = errors.New("e-mail address has not been activated")
+var ErrEmailNotActivated = util.NewInvalidArgumentErrorf("e-mail address has not been activated")
// ErrEmailCharIsNotSupported e-mail address contains unsupported character
type ErrEmailCharIsNotSupported struct {
diff --git a/models/user/openid.go b/models/user/openid.go
index 1946705048..596ff182bc 100644
--- a/models/user/openid.go
+++ b/models/user/openid.go
@@ -5,7 +5,6 @@ package user
import (
"context"
- "errors"
"fmt"
"code.gitea.io/gitea/models/db"
@@ -13,7 +12,7 @@ import (
)
// ErrOpenIDNotExist openid is not known
-var ErrOpenIDNotExist = errors.New("OpenID is unknown")
+var ErrOpenIDNotExist = util.NewNotExistErrorf("OpenID is unknown")
// UserOpenID is the list of all OpenID identities of a user.
// Since this is a middle table, name it OpenID is not suitable, so we ignore the lint here