mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-04 09:19:06 +01:00
Fix nil checking on typed interface (#17598)
* Fix nil checking on typed interface - Partially resoles #17596 - Resolves SA4023 errors. - Ensure correctly that typed interface are nil. * Remove unnecessary code `NewBleveIndexer` will never return nil, even on errors. * Patch `NewBleveIndexer` * Fix low-level functions * Remove deadcode * Fix GetSession * Close Elastic search when err isn't nil * Update elastic_search.go Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
253d9e4158
commit
ab1379743e
4 changed files with 8 additions and 15 deletions
|
@ -173,6 +173,10 @@ func NewBleveIndexer(indexDir string) (*BleveIndexer, bool, error) {
|
||||||
indexDir: indexDir,
|
indexDir: indexDir,
|
||||||
}
|
}
|
||||||
created, err := indexer.init()
|
created, err := indexer.init()
|
||||||
|
if err != nil {
|
||||||
|
indexer.Close()
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
return indexer, created, err
|
return indexer, created, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,10 @@ func NewElasticSearchIndexer(url, indexerName string) (*ElasticSearchIndexer, bo
|
||||||
indexerAliasName: indexerName,
|
indexerAliasName: indexerName,
|
||||||
}
|
}
|
||||||
exists, err := indexer.init()
|
exists, err := indexer.init()
|
||||||
|
if err != nil {
|
||||||
|
indexer.Close()
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
return indexer, !exists, err
|
return indexer, !exists, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -185,9 +185,6 @@ func Init() {
|
||||||
|
|
||||||
rIndexer, populate, err = NewBleveIndexer(setting.Indexer.RepoPath)
|
rIndexer, populate, err = NewBleveIndexer(setting.Indexer.RepoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if rIndexer != nil {
|
|
||||||
rIndexer.Close()
|
|
||||||
}
|
|
||||||
cancel()
|
cancel()
|
||||||
indexer.Close()
|
indexer.Close()
|
||||||
close(waitChannel)
|
close(waitChannel)
|
||||||
|
@ -205,9 +202,6 @@ func Init() {
|
||||||
|
|
||||||
rIndexer, populate, err = NewElasticSearchIndexer(setting.Indexer.RepoConnStr, setting.Indexer.RepoIndexerName)
|
rIndexer, populate, err = NewElasticSearchIndexer(setting.Indexer.RepoConnStr, setting.Indexer.RepoIndexerName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if rIndexer != nil {
|
|
||||||
rIndexer.Close()
|
|
||||||
}
|
|
||||||
cancel()
|
cancel()
|
||||||
indexer.Close()
|
indexer.Close()
|
||||||
close(waitChannel)
|
close(waitChannel)
|
||||||
|
|
|
@ -130,14 +130,6 @@ func Recovery() func(next http.Handler) http.Handler {
|
||||||
log.Error("%v", combinedErr)
|
log.Error("%v", combinedErr)
|
||||||
|
|
||||||
sessionStore := session.GetSession(req)
|
sessionStore := session.GetSession(req)
|
||||||
if sessionStore == nil {
|
|
||||||
if setting.IsProd {
|
|
||||||
http.Error(w, http.StatusText(500), 500)
|
|
||||||
} else {
|
|
||||||
http.Error(w, combinedErr, 500)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var lc = middleware.Locale(w, req)
|
var lc = middleware.Locale(w, req)
|
||||||
var store = dataStore{
|
var store = dataStore{
|
||||||
|
|
Loading…
Reference in a new issue