{"record":{"id":"b2f4656ec167fcb9","repo":"googleapis/mcp-toolbox","slug":"unable-to-execute-query-w-b2f465","errorCode":null,"errorMessage":"unable to execute query: %w","messagePattern":"unable to execute query: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/couchbase/couchbase.go","lineNumber":125,"sourceCode":"func (s *Source) ToConfig() sources.SourceConfig {\n\treturn s.Config\n}\n\nfunc (s *Source) CouchbaseScope() *gocb.Scope {\n\treturn s.Scope\n}\n\nfunc (s *Source) CouchbaseQueryScanConsistency() uint {\n\treturn s.QueryScanConsistency\n}\n\nfunc (s *Source) RunSQL(statement string, params parameters.ParamValues) (any, error) {\n\tresults, err := s.CouchbaseScope().Query(statement, &gocb.QueryOptions{\n\t\tScanConsistency: gocb.QueryScanConsistency(s.CouchbaseQueryScanConsistency()),\n\t\tNamedParameters: params.AsMap(),\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to execute query: %w\", err)\n\t}\n\n\tout := []any{}\n\tfor results.Next() {\n\t\tvar result json.RawMessage\n\t\terr := results.Row(&result)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error processing row: %w\", err)\n\t\t}\n\t\tout = append(out, result)\n\t}\n\treturn out, nil\n}\n\nfunc (r Config) createCouchbaseOptions() (gocb.ClusterOptions, error) {\n\tcbOpts := gocb.ClusterOptions{}\n\n\tif r.Username != \"\" {","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/couchbase/couchbase.go#L107-L143","documentation":"Returned by Source.RunSQL when the Couchbase N1QL query (scope.Query) call itself fails. The library wraps the gocb error as 'unable to execute query: %w'. This covers query-submission failures: malformed N1QL syntax, missing index, bucket/scope errors, authentication, or network failures — not row decoding.","triggerScenarios":"Calling RunSQL with a statement that fails at the query service: syntax error in N1QL, nonexistent keyspace/scope, missing primary/secondary index, invalid named parameters, query service unreachable, or credentials lacking query privileges.","commonSituations":"SQL-habit syntax not valid in N1QL, missing primary index on the bucket (common new-bucket mistake), wrong scan consistency setting value, Couchbase connection config pointing at wrong cluster, RBAC role missing for the user.","solutions":["Run the statement in the Couchbase web console Query tab to see the raw N1QL error","Create missing indexes: CREATE PRIMARY INDEX ON `bucket`.`scope`.`collection` if 'no index available' appears","Verify N1QL syntax — Couchbase is not ANSI SQL; adjust unsupported clauses","Check the user's RBAC roles (Query Select etc.) and cluster connectivity/scan-consistency config"],"exampleFix":"// before (RunSQL statement)\nSELECT * FROM users WHERE age > 21;\n// fails without an index\n// after\nCREATE PRIMARY INDEX ON `travel-sample`.inventory.users;\nSELECT * FROM `travel-sample`.inventory.users WHERE age > 21;","handlingStrategy":"try-catch","validationCode":"// Validate statement and index existence before running\n// 1. Sanity-check N1QL syntax in the Couchbase console.\n// 2. Programmatically verify a primary index exists:\nq := \"SELECT COUNT(*) AS idx FROM system:indexes WHERE keyspace_id = 'users' AND state = 'online'\"\n// run via the same SDK; if 0, run:\n// CREATE PRIMARY INDEX ON `bucket`.`scope`.`users`","typeGuard":null,"tryCatchPattern":"results, err := scope.Query(statement, opts)\nif err != nil {\n\tvar qErr *gocb.QueryError\n\tif errors.As(err, &qErr) {\n\t\tif strings.Contains(qErr.Error(), \"No index available\") {\n\t\t\t// create primary index or add a secondary index, then retry\n\t\t}\n\t\tif strings.Contains(qErr.Error(), \"syntax error\") {\n\t\t\t// surface statement to the user; N1QL != ANSI SQL\n\t\t}\n\t}\n\treturn nil, fmt.Errorf(\"unable to execute query: %w\", err)\n}","preventionTips":["Create primary/secondary indexes before querying collections","Test statements in the Couchbase Query tab first","Grant the connecting user proper RBAC query roles","Validate named parameter names against placeholders ($name) in the statement"],"tags":["couchbase","n1ql","query","database"],"backgroundTag":"query-execution-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}