diff options
author | Unknwon <u@gogs.io> | 2015-03-16 04:04:27 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-03-16 04:04:27 -0400 |
commit | 588f3215c6c4a82c7ad9cbd2cc6a5683d0ca3cc2 (patch) | |
tree | 3c62e7d0e50bf3d4046ecf07fd33063a3d8958ac /models | |
parent | 471b8a18ab73b181b0d6769e2bd95111afd0e9d3 (diff) | |
download | gitea-588f3215c6c4a82c7ad9cbd2cc6a5683d0ca3cc2.tar.gz gitea-588f3215c6c4a82c7ad9cbd2cc6a5683d0ca3cc2.zip |
#1040: dashboard no longer accessible when repo is missing
Diffstat (limited to 'models')
-rw-r--r-- | models/access.go | 6 | ||||
-rw-r--r-- | models/error.go | 31 | ||||
-rw-r--r-- | models/repo.go | 9 |
3 files changed, 41 insertions, 5 deletions
diff --git a/models/access.go b/models/access.go index f353c39a2f..ea2f7f7b4b 100644 --- a/models/access.go +++ b/models/access.go @@ -6,6 +6,8 @@ package models import ( "fmt" + + "github.com/gogits/gogs/modules/log" ) type AccessMode int @@ -77,6 +79,10 @@ func (u *User) GetAccessibleRepositories() (map[*Repository]AccessMode, error) { for _, access := range accesses { repo, err := GetRepositoryById(access.RepoID) if err != nil { + if IsErrRepoNotExist(err) { + log.Error(4, "%v", err) + continue + } return nil, err } if err = repo.GetOwner(); err != nil { diff --git a/models/error.go b/models/error.go new file mode 100644 index 0000000000..6f1a366cb4 --- /dev/null +++ b/models/error.go @@ -0,0 +1,31 @@ +// Copyright 2015 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 models + +import ( + "fmt" +) + +// __________ .__ __ +// \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__. +// | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | | +// | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ | +// |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____| +// \/ \/|__| \/ \/ + +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) +} diff --git a/models/repo.go b/models/repo.go index 7abb793e5f..2718970f18 100644 --- a/models/repo.go +++ b/models/repo.go @@ -35,7 +35,6 @@ const ( var ( ErrRepoAlreadyExist = errors.New("Repository already exist") - ErrRepoNotExist = errors.New("Repository does not exist") ErrRepoFileNotExist = errors.New("Repository file does not exist") ErrRepoNameIllegal = errors.New("Repository name contains illegal characters") ErrRepoFileNotLoaded = errors.New("Repository file not loaded") @@ -758,7 +757,7 @@ func DeleteRepository(uid, repoID int64, userName string) error { if err != nil { return err } else if !has { - return ErrRepoNotExist + return ErrRepoNotExist{repoID, uid, ""} } // In case is a organization. @@ -875,18 +874,18 @@ func GetRepositoryByName(uid int64, repoName string) (*Repository, error) { if err != nil { return nil, err } else if !has { - return nil, ErrRepoNotExist + return nil, ErrRepoNotExist{0, uid, repoName} } return repo, err } func getRepositoryById(e Engine, id int64) (*Repository, error) { - repo := &Repository{} + repo := new(Repository) has, err := e.Id(id).Get(repo) if err != nil { return nil, err } else if !has { - return nil, ErrRepoNotExist + return nil, ErrRepoNotExist{id, 0, ""} } return repo, nil } |