Browse Source

error: move ErrRepoNotExist -> errors.RepoNotExist

pull/4343/head
Unknwon 8 years ago
parent
commit
beee6e03b1
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 2
      cmd/serv.go
  2. 4
      models/access.go
  3. 15
      models/error.go
  4. 15
      models/errors/repo.go
  5. 2
      models/pull.go
  6. 10
      models/repo.go
  7. 4
      modules/context/repo.go
  8. 3
      routers/api/v1/admin/org_repo.go
  9. 2
      routers/api/v1/api.go
  10. 2
      routers/api/v1/repo/repo.go
  11. 2
      routers/org/teams.go
  12. 2
      routers/repo/http.go
  13. 4
      routers/repo/pull.go

2
cmd/serv.go

@ -162,7 +162,7 @@ func runServ(c *cli.Context) error {
repo, err := models.GetRepositoryByName(owner.ID, repoName)
if err != nil {
if models.IsErrRepoNotExist(err) {
if errors.IsRepoNotExist(err) {
fail(_ACCESS_DENIED_MESSAGE, "Repository does not exist: %s/%s", owner.Name, repoName)
}
fail("Internal error", "Fail to get repository: %v", err)

4
models/access.go

@ -8,6 +8,8 @@ import (
"fmt"
log "gopkg.in/clog.v1"
"github.com/gogits/gogs/models/errors"
)
type AccessMode int
@ -109,7 +111,7 @@ func (u *User) GetRepositoryAccesses() (map[*Repository]AccessMode, error) {
for _, access := range accesses {
repo, err := GetRepositoryByID(access.RepoID)
if err != nil {
if IsErrRepoNotExist(err) {
if errors.IsRepoNotExist(err) {
log.Error(4, "GetRepositoryByID: %v", err)
continue
}

15
models/error.go

@ -305,21 +305,6 @@ func (err ErrLastOrgOwner) Error() string {
// |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
// \/ \/|__| \/ \/
type ErrRepoNotExist struct {
ID int64
UID int64
Name string
}
func IsErrRepoNotExist(err error) bool {
_, ok := err.(ErrRepoNotExist)
return ok
}
func (err ErrRepoNotExist) Error() string {
return fmt.Sprintf("repository does not exist [id: %d, uid: %d, name: %s]", err.ID, err.UID, err.Name)
}
type ErrRepoAlreadyExist struct {
Uname string
Name string

15
models/errors/repo.go

@ -6,6 +6,21 @@ 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 InvalidRepoReference struct {
Ref string
}

2
models/pull.go

@ -88,7 +88,7 @@ func (pr *PullRequest) AfterSet(colName string, _ xorm.Cell) {
func (pr *PullRequest) loadAttributes(e Engine) (err error) {
if pr.HeadRepo == nil {
pr.HeadRepo, err = getRepositoryByID(e, pr.HeadRepoID)
if err != nil && !IsErrRepoNotExist(err) {
if err != nil && !errors.IsRepoNotExist(err) {
return fmt.Errorf("getRepositoryByID.(HeadRepo) [%d]: %v", pr.HeadRepoID, err)
}
}

10
models/repo.go

@ -1366,7 +1366,7 @@ func DeleteRepository(uid, repoID int64) error {
if err != nil {
return err
} else if !has {
return ErrRepoNotExist{repoID, uid, ""}
return errors.RepoNotExist{repoID, uid, ""}
}
// In case is a organization.
@ -1503,9 +1503,9 @@ func GetRepositoryByName(ownerID int64, name string) (*Repository, error) {
if err != nil {
return nil, err
} else if !has {
return nil, ErrRepoNotExist{0, ownerID, name}
return nil, errors.RepoNotExist{0, ownerID, name}
}
return repo, err
return repo, repo.LoadAttributes()
}
func getRepositoryByID(e Engine, id int64) (*Repository, error) {
@ -1514,9 +1514,9 @@ func getRepositoryByID(e Engine, id int64) (*Repository, error) {
if err != nil {
return nil, err
} else if !has {
return nil, ErrRepoNotExist{id, 0, ""}
return nil, errors.RepoNotExist{id, 0, ""}
}
return repo, nil
return repo, repo.loadAttributes(e)
}
// GetRepositoryByID returns the repository by given id if exists.

4
modules/context/repo.go

@ -111,7 +111,7 @@ func (r *Repository) PullRequestURL(baseBranch, headBranch string) string {
func RetrieveBaseRepo(ctx *Context, repo *models.Repository) {
// Non-fork repository will not return error in this method.
if err := repo.GetBaseRepo(); err != nil {
if models.IsErrRepoNotExist(err) {
if errors.IsRepoNotExist(err) {
repo.IsFork = false
repo.ForkID = 0
return
@ -180,7 +180,7 @@ func RepoAssignment() macaron.Handler {
// Get repository.
repo, err := models.GetRepositoryByName(owner.ID, repoName)
if err != nil {
if models.IsErrRepoNotExist(err) {
if errors.IsRepoNotExist(err) {
if ctx.Query("go-get") == "1" {
earlyResponseForGoGetMeta(ctx)
return

3
routers/api/v1/admin/org_repo.go

@ -6,13 +6,14 @@ package admin
import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/models/errors"
"github.com/gogits/gogs/modules/context"
)
func GetRepositoryByParams(ctx *context.APIContext) *models.Repository {
repo, err := models.GetRepositoryByName(ctx.Org.Team.OrgID, ctx.Params(":reponame"))
if err != nil {
if models.IsErrRepoNotExist(err) {
if errors.IsRepoNotExist(err) {
ctx.Status(404)
} else {
ctx.Error(500, "GetRepositoryByName", err)

2
routers/api/v1/api.go

@ -52,7 +52,7 @@ func repoAssignment() macaron.Handler {
// Get repository.
repo, err := models.GetRepositoryByName(owner.ID, repoName)
if err != nil {
if models.IsErrRepoNotExist(err) {
if errors.IsRepoNotExist(err) {
ctx.Status(404)
} else {
ctx.Error(500, "GetRepositoryByName", err)

2
routers/api/v1/repo/repo.go

@ -291,7 +291,7 @@ func parseOwnerAndRepo(ctx *context.APIContext) (*models.User, *models.Repositor
repo, err := models.GetRepositoryByName(owner.ID, ctx.Params(":reponame"))
if err != nil {
if models.IsErrRepoNotExist(err) {
if errors.IsRepoNotExist(err) {
ctx.Status(404)
} else {
ctx.Error(500, "GetRepositoryByName", err)

2
routers/org/teams.go

@ -121,7 +121,7 @@ func TeamsRepoAction(ctx *context.Context) {
var repo *models.Repository
repo, err = models.GetRepositoryByName(ctx.Org.Organization.ID, repoName)
if err != nil {
if models.IsErrRepoNotExist(err) {
if errors.IsRepoNotExist(err) {
ctx.Flash.Error(ctx.Tr("org.teams.add_nonexistent_repo"))
ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories")
return

2
routers/repo/http.go

@ -66,7 +66,7 @@ func HTTPContexter() macaron.Handler {
repo, err := models.GetRepositoryByName(owner.ID, repoName)
if err != nil {
ctx.NotFoundOrServerError("GetRepositoryByName", models.IsErrRepoNotExist, err)
ctx.NotFoundOrServerError("GetRepositoryByName", errors.IsRepoNotExist, err)
return
}

4
routers/repo/pull.go

@ -42,7 +42,7 @@ var (
func parseBaseRepository(ctx *context.Context) *models.Repository {
baseRepo, err := models.GetRepositoryByID(ctx.ParamsInt64(":repoid"))
if err != nil {
ctx.NotFoundOrServerError("GetRepositoryByID", models.IsErrRepoNotExist, err)
ctx.NotFoundOrServerError("GetRepositoryByID", errors.IsRepoNotExist, err)
return nil
}
@ -718,7 +718,7 @@ func parseOwnerAndRepo(ctx *context.Context) (*models.User, *models.Repository)
repo, err := models.GetRepositoryByName(owner.ID, ctx.Params(":reponame"))
if err != nil {
ctx.NotFoundOrServerError("GetRepositoryByName", models.IsErrRepoNotExist, err)
ctx.NotFoundOrServerError("GetRepositoryByName", errors.IsRepoNotExist, err)
return nil, nil
}

Loading…
Cancel
Save