Skip to content

Commit

Permalink
GOCBC-1494: Remove query index management error parsing
Browse files Browse the repository at this point in the history
Motivation
----------
We have improved query error parsing in gocbcore and it now
handles cases like index already exists etc...

Changes
-------
Remove query index management error parsing.

Change-Id: I53f1ae86648c48f514e0d81909afe7c977d06742
Reviewed-on: https://review.couchbase.org/c/gocb/+/202504
Reviewed-by: Dimitris Christodoulou <dimitris.christodoulou@couchbase.com>
Tested-by: Charles Dixon <chvckd@gmail.com>
  • Loading branch information
chvck committed Dec 12, 2023
1 parent 24e3ad7 commit e2153b3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 48 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/couchbase/gocb/v2

require (
github.com/couchbase/gocbcore/v10 v10.3.0
github.com/couchbase/gocbcore/v10 v10.3.1-0.20231212155116-d936c9049d5c
github.com/couchbase/gocbcoreps v0.1.0
github.com/couchbase/goprotostellar v1.0.0
github.com/couchbaselabs/gocaves/client v0.0.0-20230404095311-05e3ba4f0259
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZx
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/couchbase/gocbcore/v10 v10.3.0 h1:cu5KWP5Yq9cANw0UitpKWmb8mv9NDhC0ApIf9rMrVq8=
github.com/couchbase/gocbcore/v10 v10.3.0/go.mod h1:lYQIIk+tzoMcwtwU5GzPbDdqEkwkH3isI2rkSpfL0oM=
github.com/couchbase/gocbcore/v10 v10.3.1-0.20231212155116-d936c9049d5c h1:NWhbDPAOIX2Wh6Fd56NH1x//dHaAI7Ko0N7SGzR1VwA=
github.com/couchbase/gocbcore/v10 v10.3.1-0.20231212155116-d936c9049d5c/go.mod h1:lYQIIk+tzoMcwtwU5GzPbDdqEkwkH3isI2rkSpfL0oM=
github.com/couchbase/gocbcoreps v0.1.0 h1:9+Qq+H/YXYn+H6f5A5MndUv40qdCwPwoJjinHolxq2g=
github.com/couchbase/gocbcoreps v0.1.0/go.mod h1:LjH33s/LNVBAwVU1Ka/YU3cLkuAyFC2dzGGiValJ5oY=
github.com/couchbase/goprotostellar v1.0.0 h1:umfH4hOxrUS/0QY1AkdoVcpp9rg7Jl+UNWzNJ3KxIHc=
Expand Down
47 changes: 2 additions & 45 deletions queryindexprovider_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -416,48 +415,6 @@ func (qpc *queryProviderCore) WatchIndexes(c *Collection, bucketName string, wat
return nil
}

func (qpc *queryProviderCore) tryParseErrorMessage(err error) error {
var qErr *QueryError
if !errors.As(err, &qErr) {
return err
}

if len(qErr.Errors) == 0 {
return err
}

firstErr := qErr.Errors[0]
var innerErr error
if firstErr.Code == 12016 {
innerErr = ErrIndexNotFound
} else if firstErr.Code == 4300 {
innerErr = ErrIndexExists
} else {
// Older server versions don't return meaningful error codes when it comes to index management
// so we need to go spelunking.
msg := strings.ToLower(firstErr.Message)
if match, err := regexp.MatchString(".*?ndex .*? not found.*", msg); err == nil && match {
innerErr = ErrIndexNotFound
} else if match, err := regexp.MatchString(".*?ndex .*? already exists.*", msg); err == nil && match {
innerErr = ErrIndexExists
}
}

if innerErr == nil {
return err
}

return QueryError{
InnerError: innerErr,
Statement: qErr.Statement,
ClientContextID: qErr.ClientContextID,
Errors: qErr.Errors,
Endpoint: qErr.Endpoint,
RetryReasons: qErr.RetryReasons,
RetryAttempts: qErr.RetryAttempts,
}
}

func (qpc *queryProviderCore) doQuery(c *Collection, q string, opts *QueryOptions) ([][]byte, error) {
if opts.Timeout == 0 {
opts.Timeout = qpc.timeouts.ManagementTimeout
Expand All @@ -471,7 +428,7 @@ func (qpc *queryProviderCore) doQuery(c *Collection, q string, opts *QueryOption

result, err := qpc.Query(q, scope, opts)
if err != nil {
return nil, qpc.tryParseErrorMessage(err)
return nil, err
}

var rows [][]byte
Expand All @@ -486,7 +443,7 @@ func (qpc *queryProviderCore) doQuery(c *Collection, q string, opts *QueryOption
}
err = result.Err()
if err != nil {
return nil, qpc.tryParseErrorMessage(err)
return nil, err
}

return rows, nil
Expand Down

0 comments on commit e2153b3

Please sign in to comment.