Skip to content

Commit

Permalink
Merge remote-tracking branch 'couchbase/unstable' into HEAD
Browse files Browse the repository at this point in the history
http://ci-eventing.northscale.in/eventing-21.11.2019-20.52.pass.html

Change-Id: Ieebbd0826119f74a089f3cd42d8a3418ab97e6b3
  • Loading branch information
jeelanp2003 committed Nov 22, 2019
2 parents ba3b191 + cafc1fe commit 6ad5944
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 30 deletions.
4 changes: 3 additions & 1 deletion features/query/include/query-iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class Iterator {
bool is_error{false};
bool is_client_auth_error{false};
bool is_client_error{false}; // Error reported by SDK client
bool is_query_error{false}; // Error reported by Query server
std::string client_error;
bool is_query_error{false}; // Error reported by Query server
std::string query_error;
bool is_last{false};
std::string data;

Expand Down
9 changes: 7 additions & 2 deletions features/query/include/query-row.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@
namespace Query {
struct Row {
Row(bool is_done, bool is_error, bool is_auth_error, bool is_client_error,
bool is_query_error, lcb_error_t err_code, const std::string &data)
const std::string &client_error, bool is_query_error,
const std::string &query_error, lcb_error_t err_code,
const std::string &data)
: is_done(is_done), is_error(is_error),
is_client_auth_error(is_auth_error), is_client_error(is_client_error),
is_query_error(is_query_error), err_code(err_code), data(data) {}
client_error(client_error), is_query_error(is_query_error),
query_error(query_error), err_code(err_code), data(data) {}

bool is_done{false};
bool is_error{false};
bool is_client_auth_error{false};
bool is_client_error{false};
const std::string &client_error;
bool is_query_error{false};
const std::string &query_error;
lcb_error_t err_code{LCB_SUCCESS};
const std::string &data;
};
Expand Down
36 changes: 23 additions & 13 deletions features/query/src/helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,25 +202,33 @@ Query::Helper::GetErrorCodes(const v8::Local<v8::Value> &errors_val) {

Query::Helper::ErrorCodesInfo
Query::Helper::GetErrorCodes(const std::string &error) {
if (error.empty()) {
return {true, "error message is empty"};
}

v8::HandleScope handle_scope(isolate_);
auto context = context_.Get(isolate_);
std::vector<int64_t> errors;
std::stringstream msg;

v8::Local<v8::Value> error_val;
if (!TO_LOCAL(v8::JSON::Parse(isolate_, v8Str(isolate_, error)),
&error_val)) {
return {true, "Unable to parse error JSON"};
msg << "Unable to parse error JSON : " << RU(error);
return {true, msg.str()};
}

v8::Local<v8::Object> error_obj;
if (!TO_LOCAL(error_val->ToObject(context), &error_obj)) {
return {true, "Unable to cast error to Object"};
msg << "Unable to cast error to Object : " << RU(error);
return {true, msg.str()};
}

v8::Local<v8::Value> errors_val;
if (!TO_LOCAL(error_obj->Get(context, v8Str(isolate_, "errors")),
&errors_val)) {
return {true, "Unable to read errors property from message Object"};
msg << "Unable to read errors property from message Object : " << RU(error);
return {true, msg.str()};
}
return GetErrorCodes(errors_val);
}
Expand All @@ -239,20 +247,22 @@ void Query::Helper::HandleRowError(const Query::Row &row) {
if (row.is_client_auth_error) {
comm->Refresh();
}
// Error reported by RowCallback (coming from query server)
if (row.is_query_error) {
if (auto acc_info = AccountLCBError(row.data); acc_info.is_fatal) {
js_exception->ThrowN1QLError(acc_info.msg);
return;
}
js_exception->ThrowN1QLError(row.data);
return;
}

std::stringstream err_msg;
// Error reported by RowCallback (coming from LCB client)
if (row.is_client_error) {
AccountLCBError(row.err_code);
js_exception->ThrowN1QLError(row.data);
err_msg << "SDK error : " << row.client_error;
}

// Error reported by RowCallback (coming from query server)
if (row.is_query_error) {
err_msg << " Query error : " << row.query_error;
if (auto acc_info = AccountLCBError(row.query_error); acc_info.is_fatal) {
err_msg << " Error accounting LCB : " << acc_info.msg;
}
}
js_exception->ThrowN1QLError(err_msg.str());
}

std::string Query::Helper::ErrorFormat(const std::string &message,
Expand Down
9 changes: 7 additions & 2 deletions features/query/src/iterable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// or implied. See the License for the specific language governing
// permissions and limitations under the License.

#include <sstream>
#include <v8.h>

#include "comm.h"
Expand Down Expand Up @@ -202,16 +203,20 @@ Query::IterableResult::NewObject(const Query::Row &row) {
return {handle_scope.Escape(result_obj)};
}

std::stringstream err_msg;
v8::Local<v8::Value> value_val;
// TODO : If JSON parse fails, try to provide (row, col) information
if (!TO_LOCAL(v8::JSON::Parse(isolate_, v8Str(isolate_, row.data)),
&value_val)) {
return {true, "Unable to parse query row as JSON"};
err_msg << "Unable to parse query row as JSON : " << RU(row.data);
return {true, err_msg.str()};
}
result = false;
if (!TO(result_obj->Set(context, v8Str(isolate_, "value"), value_val),
&result)) {
return {true, "Unable to set value on iterable result object"};
err_msg << "Unable to set value on iterable result object : "
<< RU(row.data);
return {true, err_msg.str()};
}
return {handle_scope.Escape(result_obj)};
}
Expand Down
20 changes: 8 additions & 12 deletions features/query/src/iterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ void Query::Iterator::RowCallback(lcb_t connection, int,
cursor->is_client_auth_error =
cursor->is_error && (resp->rc == LCB_AUTH_ERROR);

// Ensure that the most specific error is delivered in the case where both
// client and query errors occur. That is, we expose the client error only
// when there is no query error
if (cursor->is_client_error && !cursor->is_query_error) {
cursor->data = lcb_strerror(connection, resp->rc);
if (cursor->is_client_error) {
cursor->client_error = lcb_strerror(connection, resp->rc);
}
if (cursor->is_query_error) {
cursor->query_error = cursor->data;
}

LOG(logDebug) << "Query::Iterator::RowCallback data : " << RU(cursor->data)
Expand Down Expand Up @@ -167,13 +167,9 @@ void Query::Iterator::Cursor::YieldTo(const ExecutionControl control) {
}

Query::Row Query::Iterator::Cursor::GetRow() const {
return {is_last,
is_error,
is_client_auth_error,
is_client_error,
is_query_error,
client_err_code,
data};
return {is_last, is_error, is_client_auth_error,
is_client_error, client_error, is_query_error,
query_error, client_err_code, data};
}

Query::Row Query::Iterator::Cursor::GetRowAsFinal() const {
Expand Down

0 comments on commit 6ad5944

Please sign in to comment.