From 0de64ed13944f142020b93415704d33a248b25f3 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Mon, 10 Jul 2017 18:17:58 +0800 Subject: [PATCH] bug fix --- src/common/dao/repository.go | 9 ++++++--- src/common/utils/ldap/ldap.go | 3 +++ src/common/utils/registry/auth/tokenauthorizer.go | 3 +++ src/ui/api/member.go | 2 ++ src/ui/service/notifications/registry/handler.go | 4 ++++ 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/common/dao/repository.go b/src/common/dao/repository.go index d6da58f82..d5a61cf4c 100644 --- a/src/common/dao/repository.go +++ b/src/common/dao/repository.go @@ -79,10 +79,13 @@ func IncreasePullCount(name string) (err error) { "pull_count": orm.ColValue(orm.ColAdd, 1), "update_time": time.Now(), }) - if num == 0 { - err = fmt.Errorf("Failed to increase repository pull count with name: %s %s", name, err.Error()) + if err != nil { + return err } - return err + if num == 0 { + return fmt.Errorf("Failed to increase repository pull count with name: %s", name) + } + return nil } //RepositoryExists returns whether the repository exists according to its name. diff --git a/src/common/utils/ldap/ldap.go b/src/common/utils/ldap/ldap.go index 7bda13a54..dc1a7cd97 100644 --- a/src/common/utils/ldap/ldap.go +++ b/src/common/utils/ldap/ldap.go @@ -48,6 +48,9 @@ func GetSystemLdapConf() (models.LdapConf, error) { } ldap, err := config.LDAP() + if err != nil { + return ldapConfs, err + } ldapConfs.LdapURL = ldap.URL ldapConfs.LdapSearchDn = ldap.SearchDN diff --git a/src/common/utils/registry/auth/tokenauthorizer.go b/src/common/utils/registry/auth/tokenauthorizer.go index 118aa3444..3bbc74f14 100644 --- a/src/common/utils/registry/auth/tokenauthorizer.go +++ b/src/common/utils/registry/auth/tokenauthorizer.go @@ -164,6 +164,9 @@ func (s *standardTokenAuthorizer) generateToken(realm, service string, scopes [] realm = s.tokenURL(realm) tk, err := getToken(s.client, s.credential, realm, service, scopes) + if err != nil { + return "", 0, nil, err + } if len(tk.IssuedAt) == 0 { return tk.Token, tk.ExpiresIn, nil, nil diff --git a/src/ui/api/member.go b/src/ui/api/member.go index d4f7b6841..864fcd287 100644 --- a/src/ui/api/member.go +++ b/src/ui/api/member.go @@ -64,6 +64,8 @@ func (pma *ProjectMemberAPI) Prepare() { } else { text += fmt.Sprintf("%d", pid) } + pma.HandleBadRequest(text) + return } project, err := pma.ProjectMgr.Get(pid) if err != nil { diff --git a/src/ui/service/notifications/registry/handler.go b/src/ui/service/notifications/registry/handler.go index 20092f647..2f60622bf 100644 --- a/src/ui/service/notifications/registry/handler.go +++ b/src/ui/service/notifications/registry/handler.go @@ -70,6 +70,10 @@ func (n *NotificationHandler) Post() { log.Errorf("failed to get project by name %s: %v", project, err) return } + if pro == nil { + log.Warningf("project %s not found", project) + continue + } go func() { if err := dao.AddAccessLog(models.AccessLog{