From 105a9af2dc4d56032a66b85ff3e96fad3baa3ab6 Mon Sep 17 00:00:00 2001 From: Luis Remis Date: Wed, 10 Jul 2019 13:12:08 -0700 Subject: [PATCH 1/2] Remove '\n' from PMGDQH error messages --- src/PMGDQueryHandler.cc | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/PMGDQueryHandler.cc b/src/PMGDQueryHandler.cc index d36cb775..519f4f59 100644 --- a/src/PMGDQueryHandler.cc +++ b/src/PMGDQueryHandler.cc @@ -188,7 +188,7 @@ int PMGDQueryHandler::add_node(const protobufs::AddNode &cn, { long id = cn.identifier(); if (id >= 0 && _cached_nodes.find(id) != _cached_nodes.end()) { - set_response(response, PMGDCmdResponse::Error, "Reuse of _ref value\n"); + set_response(response, PMGDCmdResponse::Error, "Reuse of _ref value"); return -1; } @@ -246,7 +246,7 @@ int PMGDQueryHandler::update_node(const protobufs::UpdateNode &un, if (it == _cached_nodes.end()) { if (!query) { - set_response(response, PMGDCmdResponse::Error, "Undefined _ref value used in update\n"); + set_response(response, PMGDCmdResponse::Error, "Undefined _ref value used in update"); return -1; } else { @@ -257,7 +257,7 @@ int PMGDQueryHandler::update_node(const protobufs::UpdateNode &un, if (qn_id >= 0) it = _cached_nodes.find(qn_id); else { - set_response(response, PMGDCmdResponse::Error, "Undefined _ref value used in update\n"); + set_response(response, PMGDCmdResponse::Error, "Undefined _ref value used in update"); return -1; } } @@ -287,7 +287,7 @@ int PMGDQueryHandler::add_edge(const protobufs::AddEdge &ce, response->set_node_edge(false); long id = ce.identifier(); if (id >= 0 && _cached_edges.find(id) != _cached_edges.end()) { - set_response(response, PMGDCmdResponse::Error, "Reuse of _ref value\n"); + set_response(response, PMGDCmdResponse::Error, "Reuse of _ref value"); return -1; } @@ -367,7 +367,7 @@ int PMGDQueryHandler::update_edge(const protobufs::UpdateEdge &ue, if (it == _cached_edges.end()) { if (!query) { - set_response(response, PMGDCmdResponse::Error, "Undefined _ref value used in update\n"); + set_response(response, PMGDCmdResponse::Error, "Undefined _ref value used in update"); return -1; } else { @@ -378,7 +378,7 @@ int PMGDQueryHandler::update_edge(const protobufs::UpdateEdge &ue, if (qe_id >= 0) it = _cached_edges.find(qe_id); else { - set_response(response, PMGDCmdResponse::Error, "Undefined _ref value used in update\n"); + set_response(response, PMGDCmdResponse::Error, "Undefined _ref value used in update"); return -1; } } @@ -451,7 +451,7 @@ int PMGDQueryHandler::query_node(const protobufs::QueryNode &qn, long id = qn.identifier(); if (id >= 0 && _cached_nodes.find(id) != _cached_nodes.end()) { set_response(response, PMGDCmdResponse::Error, - "Reuse of _ref value\n"); + "Reuse of _ref value"); return -1; } @@ -462,7 +462,7 @@ int PMGDQueryHandler::query_node(const protobufs::QueryNode &qn, if (link.nb_unique()) { // TODO Add support for unique neighbors across iterators set_response(response, PMGDCmdResponse::Error, - "Non-repeated neighbors not supported\n"); + "Non-repeated neighbors not supported"); return -1; } @@ -470,7 +470,7 @@ int PMGDQueryHandler::query_node(const protobufs::QueryNode &qn, auto start = _cached_nodes.find(start_id); if (start == _cached_nodes.end()) { set_response(response, PMGDCmdResponse::Error, - "Undefined _ref value used in link\n"); + "Undefined _ref value used in link"); return -1; } start_ni = start->second; @@ -499,7 +499,7 @@ int PMGDQueryHandler::query_node(const protobufs::QueryNode &qn, : search.eval_nodes(); if (!bool(ni) && id >= 0) { set_response(response, PMGDCmdResponse::Empty, - "Null search iterator\n"); + "Null search iterator"); if (has_link) start_ni->reset(); return -1; @@ -528,7 +528,7 @@ int PMGDQueryHandler::query_node(const protobufs::QueryNode &qn, tni->next(); if (bool(*tni)) { // Not unique and that is an error here. set_response(response, PMGDCmdResponse::NotUnique, - "Query response not unique\n"); + "Query response not unique"); if (has_link) start_ni->reset(); delete tni; @@ -572,14 +572,14 @@ int PMGDQueryHandler::query_edge(const protobufs::QueryEdge &qe, if (qc.p_op() == protobufs::Or) { set_response(response, PMGDCmdResponse::Error, - "Or operation not implemented\n"); + "Or operation not implemented"); return -1; } long id = qe.identifier(); if (id >= 0 && _cached_edges.find(id) != _cached_edges.end()) { set_response(response, PMGDCmdResponse::Error, - "Reuse of _ref value\n"); + "Reuse of _ref value"); return -1; } @@ -615,7 +615,7 @@ int PMGDQueryHandler::query_edge(const protobufs::QueryEdge &qe, EdgeIterator ei = PMGD::EdgeIterator(new NodeEdgeIteratorImpl(search, src_ni, dest_ni)); if (!bool(ei) && id >= 0) { set_response(response, PMGDCmdResponse::Empty, - "Null search iterator\n"); + "Null search iterator"); // Make sure the src and dest Node iterators are resettled. if (src_ni != NULL) src_ni->reset(); if (dest_ni != NULL) dest_ni->reset(); @@ -642,7 +642,7 @@ int PMGDQueryHandler::query_edge(const protobufs::QueryEdge &qe, tei->next(); if (bool(*tei)) { // Not unique and that is an error here. set_response(response, PMGDCmdResponse::NotUnique, - "Query response not unique\n"); + "Query response not unique"); delete tei; if (src_ni != NULL) src_ni->reset(); if (dest_ni != NULL) dest_ni->reset(); @@ -818,7 +818,7 @@ void PMGDQueryHandler::build_results(Iterator &ni, } else { set_response(response, PMGDCmdResponse::Error, - "Wrong first property for sum/average\n"); + "Wrong first property for sum/average"); } break; } @@ -832,7 +832,7 @@ void PMGDQueryHandler::build_results(Iterator &ni, } default: set_response(response, PMGDCmdResponse::Error, - "Unknown operation type for query\n"); + "Unknown operation type for query"); } } From de5cb8d39043d955cab77421a946c407c9410c3d Mon Sep 17 00:00:00 2001 From: Luis Remis Date: Mon, 15 Jul 2019 15:04:34 -0700 Subject: [PATCH 2/2] Fix error return message in QueryHandler --- src/QueryHandler.cc | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/QueryHandler.cc b/src/QueryHandler.cc index b797ce92..622330e0 100644 --- a/src/QueryHandler.cc +++ b/src/QueryHandler.cc @@ -303,7 +303,9 @@ void QueryHandler::process_query(protobufs::queryMessage& proto_query, std::cerr << "End Failed Query: " << std::endl; exception_error["info"] = error_msg.str(); exception_error["status"] = RSCommand::Error; - proto_res.set_json(fastWriter.write(exception_error)); + Json::Value response; + response.append(exception_error); + proto_res.set_json(fastWriter.write(response)); }; try { @@ -368,13 +370,20 @@ void QueryHandler::process_query(protobufs::queryMessage& proto_query, Json::Value& tx_responses = pmgd_query.run(); - if (tx_responses.size() != root.size()) { // error - cmd_current = "Transaction"; - cmd_result = tx_responses; - cmd_result["info"] = "Failed PMGDTransaction"; + if (!tx_responses.isArray() || tx_responses.size() != root.size()) { + Json::StyledWriter writer; + std::cerr << "PMGD Response:" << std::endl; + std::cerr << writer.write(tx_responses) << std::endl; + + std::string tx_error_msg("Failed PMGD Transaction"); + if (!tx_responses.isArray() && tx_responses.isMember("info")) { + tx_error_msg += ": " + tx_responses["info"].asString(); + } + cmd_result["status"] = RSCommand::Error; - Json::StyledWriter w; - std::cerr << w.write(tx_responses); + cmd_result["info"] = tx_error_msg; + + cmd_current = "Transaction"; error(cmd_result, cmd_current); return; }