summaryrefslogtreecommitdiffstats
path: root/store/sql_post_store.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-03-02 14:11:59 +0000
committerCorey Hulen <corey@hulen.com>2017-03-02 09:11:59 -0500
commit2e5ebac615bfe720eee9dfab70e966f81c138a27 (patch)
treedab269cd10b8d5ba4e749494fbdf26fb85c47a87 /store/sql_post_store.go
parentd94539340397d1e0478676ad3f8c40215783880a (diff)
downloadchat-2e5ebac615bfe720eee9dfab70e966f81c138a27.tar.gz
chat-2e5ebac615bfe720eee9dfab70e966f81c138a27.tar.bz2
chat-2e5ebac615bfe720eee9dfab70e966f81c138a27.zip
PLT-5612: Don't show error on invalid search query. (#5596)
Log a warning to the logs, but don't show an error to the user in the WebUI, just an empty set of query results, when the fulltext search query they enter generates a syntax error from the database.
Diffstat (limited to 'store/sql_post_store.go')
-rw-r--r--store/sql_post_store.go34
1 files changed, 18 insertions, 16 deletions
diff --git a/store/sql_post_store.go b/store/sql_post_store.go
index e224f60bd..eefd251e5 100644
--- a/store/sql_post_store.go
+++ b/store/sql_post_store.go
@@ -9,6 +9,7 @@ import (
"strconv"
"strings"
+ l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/einterfaces"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
@@ -961,27 +962,28 @@ func (s SqlPostStore) Search(teamId string, userId string, params *model.SearchP
queryParams["Terms"] = terms
- _, err := s.GetReplica().Select(&posts, searchQuery, queryParams)
- if err != nil {
- result.Err = model.NewLocAppError("SqlPostStore.Search", "store.sql_post.search.app_error", nil, "teamId="+teamId+", err="+err.Error())
- }
-
list := model.NewPostList()
- for _, p := range posts {
- if searchType == "Hashtags" {
- exactMatch := false
- for _, tag := range strings.Split(p.Hashtags, " ") {
- if termMap[strings.ToUpper(tag)] {
- exactMatch = true
+ _, err := s.GetReplica().Select(&posts, searchQuery, queryParams)
+ if err != nil {
+ l4g.Warn(utils.T("store.sql_post.search.warn"), err.Error())
+ // Don't return the error to the caller as it is of no use to the user. Instead return an empty set of search results.
+ } else {
+ for _, p := range posts {
+ if searchType == "Hashtags" {
+ exactMatch := false
+ for _, tag := range strings.Split(p.Hashtags, " ") {
+ if termMap[strings.ToUpper(tag)] {
+ exactMatch = true
+ }
+ }
+ if !exactMatch {
+ continue
}
}
- if !exactMatch {
- continue
- }
+ list.AddPost(p)
+ list.AddOrder(p.Id)
}
- list.AddPost(p)
- list.AddOrder(p.Id)
}
list.MakeNonNil()