1
0
Fork 0

Response can always be a nullptr

This commit is contained in:
Andreas Streichardt 2017-06-08 14:41:33 +02:00
parent 2275fc8174
commit 73b7d67510
3 changed files with 34 additions and 32 deletions

View File

@ -1167,44 +1167,43 @@ static bool throwExceptionAfterBadSyncRequest(ClusterCommResult* res,
}
if (res->status == CL_COMM_ERROR) {
std::string errorMessage;
TRI_ASSERT(nullptr != res->result);
arangodb::basics::StringBuffer const& responseBodyBuf(res->result->getBody());
// extract error number and message from response
int errorNum = TRI_ERROR_NO_ERROR;
std::shared_ptr<VPackBuilder> builder = VPackParser::fromJson(
responseBodyBuf.c_str(), responseBodyBuf.length());
VPackSlice slice = builder->slice();
if (!slice.hasKey("error") || slice.get("error").getBoolean()) {
errorNum = TRI_ERROR_INTERNAL;
errorMessage = std::string("Error message received from shard '") +
std::string errorMessage = std::string("Error message received from shard '") +
std::string(res->shardID) +
std::string("' on cluster node '") +
std::string(res->serverID) + std::string("': ");
}
if (slice.isObject()) {
VPackSlice v = slice.get("errorNum");
if (v.isNumber()) {
if (v.getNumericValue<int>() != TRI_ERROR_NO_ERROR) {
/* if we've got an error num, error has to be true. */
TRI_ASSERT(errorNum == TRI_ERROR_INTERNAL);
errorNum = v.getNumericValue<int>();
int errorNum = TRI_ERROR_INTERNAL;
std::string errorDetailMessage = std::string("(no valid response)");
if (res->result != nullptr) {
errorNum = TRI_ERROR_NO_ERROR;
} else {
arangodb::basics::StringBuffer const& responseBodyBuf(res->result->getBody());
std::shared_ptr<VPackBuilder> builder = VPackParser::fromJson(
responseBodyBuf.c_str(), responseBodyBuf.length());
VPackSlice slice = builder->slice();
if (!slice.hasKey("error") || slice.get("error").getBoolean()) {
errorNum = TRI_ERROR_INTERNAL;
}
if (slice.isObject()) {
VPackSlice v = slice.get("errorNum");
if (v.isNumber()) {
if (v.getNumericValue<int>() != TRI_ERROR_NO_ERROR) {
/* if we've got an error num, error has to be true. */
TRI_ASSERT(errorNum == TRI_ERROR_INTERNAL);
errorNum = v.getNumericValue<int>();
}
}
v = slice.get("errorMessage");
if (v.isString()) {
errorMessage += v.copyString();
} else {
errorMessage += std::string("(no valid error in response)");
}
}
v = slice.get("errorMessage");
if (v.isString()) {
errorMessage += v.copyString();
} else {
errorMessage += std::string("(no valid error in response)");
}
} else {
errorMessage += std::string("(no valid response)");
}
if (isShutdown && errorNum == TRI_ERROR_QUERY_NOT_FOUND) {

View File

@ -485,6 +485,9 @@ void ClusterFeature::start() {
}
}
void ClusterFeature::beginShutdown() {
ClusterComm::instance()->disable();
}
void ClusterFeature::stop() {
@ -537,7 +540,6 @@ void ClusterFeature::unprepare() {
}
if (!_enableCluster) {
ClusterComm::instance()->disable();
ClusterComm::cleanup();
return;
}

View File

@ -43,6 +43,7 @@ class ClusterFeature : public application_features::ApplicationFeature {
void validateOptions(std::shared_ptr<options::ProgramOptions>) override final;
void prepare() override final;
void start() override final;
void beginShutdown() override final;
void unprepare() override final;
std::string agencyPrefix() {