How do i get cluster.Query error code using golang SDK?

    nql:=`INSERT INTO master_erp (KEY, VALUE) VALUES ("login_session::22", {"type":"login_session","cid":1,"create_date":"2020-06-11 09:00:30","status":1})
        RETURNING *`

    qr, err := cluster.Query(nql, &gocb.QueryOptions{Metrics: true})
    if err != nil {
        fmt.Println("####1", err.Error())

    // iterate over rows
    for qr.Next() {


    // always check for errors after iterating
    err = qr.Err()

    if err != nil {
        fmt.Println("####2", err.Error())

metadata, _ := qr.MetaData()

Metadata() shows only status:

but i need state and their message like i get from REST API below:

“errors”: [
“code”: 12009,
“msg”: “DML Error, possible causes include CAS mismatch or concurrent modificationFailed to perform insert - cause: Duplicate Key login_session::1”

how do i get error code: 12009 and msg value ? any suggestions or code snippet are appreciable.

Hi @mostain there isn’t actually a way to access these errors at the moment. The issue is that the query service is responding with a status code 200 and a results field so the SDK processes it thinking that there are no errors. I’ve raised to figure out a way to expose any errors returned alongside results.

@chvck thank you for your answer. i think gosdk response should be identical to query workbench output/response. then developer have prior knowledge what query going to response. this will be much more easier to work with golangsdk, i don’t like current sdk so i am writing my own simple sdk which can perform couch-base query job done.

@mostain I’m sorry to hear that you don’t like the golang SDK. Could you provide us with any feedback on why you dislike it?

@chvck yes because it is not identical as couchbase query response in workbench or in REST API.
It should be 100% identical as REST API does.

@chvck query service return with a status code 200 does not mean query is successful. see my above screenshot my query return a 200 response code but still it is failed because of duplicate entry, so without reading error number or message how any one get determination whats going on under the hood?

@mostain as above, unfortunately in this case that you are seeing you cannot get at the error. As a possible workaround until this is addressed you could try using the key value API which would definitely return the error to you.