mirror of https://gitee.com/bigwinds/arangodb
show error details in arangoimp
Conflicts: arangosh/V8Client/ImportHelper.cpp
This commit is contained in:
parent
00e6f2fc2c
commit
dd9802b1b8
|
@ -62,6 +62,7 @@ namespace triagens {
|
||||||
_maxUploadSize(maxUploadSize),
|
_maxUploadSize(maxUploadSize),
|
||||||
_lineBuffer(TRI_UNKNOWN_MEM_ZONE),
|
_lineBuffer(TRI_UNKNOWN_MEM_ZONE),
|
||||||
_outputBuffer(TRI_UNKNOWN_MEM_ZONE) {
|
_outputBuffer(TRI_UNKNOWN_MEM_ZONE) {
|
||||||
|
|
||||||
_quote = "\"";
|
_quote = "\"";
|
||||||
_separator = ",";
|
_separator = ",";
|
||||||
_createCollection = false;
|
_createCollection = false;
|
||||||
|
@ -308,8 +309,9 @@ namespace triagens {
|
||||||
}
|
}
|
||||||
|
|
||||||
double pct = 100.0 * ((double) totalRead / (double) totalLength);
|
double pct = 100.0 * ((double) totalRead / (double) totalLength);
|
||||||
if (pct >= nextProgress) {
|
if (pct >= nextProgress && totalLength >= 1024) {
|
||||||
LOGGER_INFO("processed " << totalRead << " bytes (" << std::fixed << std::setprecision(2) << pct << " %) of input file");
|
LOGGER_INFO("processed " << totalRead << " bytes (" << std::fixed << std::setprecision(2) << pct << " %) of input file");
|
||||||
|
|
||||||
nextProgress = pct + ProgressStep;
|
nextProgress = pct + ProgressStep;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -471,7 +473,7 @@ namespace triagens {
|
||||||
}
|
}
|
||||||
|
|
||||||
map<string, string> headerFields;
|
map<string, string> headerFields;
|
||||||
string url("/_api/import?" + getCollectionUrlPart() + "&line=" + StringUtils::itoa(_rowOffset));
|
string url("/_api/import?" + getCollectionUrlPart() + "&line=" + StringUtils::itoa(_rowOffset) + "&details=true");
|
||||||
SimpleHttpResult* result = _client->request(HttpRequest::HTTP_REQUEST_POST, url, _outputBuffer.c_str(), _outputBuffer.length(), headerFields);
|
SimpleHttpResult* result = _client->request(HttpRequest::HTTP_REQUEST_POST, url, _outputBuffer.c_str(), _outputBuffer.length(), headerFields);
|
||||||
|
|
||||||
handleResult(result);
|
handleResult(result);
|
||||||
|
@ -488,17 +490,17 @@ namespace triagens {
|
||||||
map<string, string> headerFields;
|
map<string, string> headerFields;
|
||||||
SimpleHttpResult* result;
|
SimpleHttpResult* result;
|
||||||
if (isArray) {
|
if (isArray) {
|
||||||
result = _client->request(HttpRequest::HTTP_REQUEST_POST, "/_api/import?type=array&" + getCollectionUrlPart(), str, len, headerFields);
|
result = _client->request(HttpRequest::HTTP_REQUEST_POST, "/_api/import?type=array&" + getCollectionUrlPart() + "&details=true", str, len, headerFields);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result = _client->request(HttpRequest::HTTP_REQUEST_POST, "/_api/import?type=documents&" + getCollectionUrlPart(), str, len, headerFields);
|
result = _client->request(HttpRequest::HTTP_REQUEST_POST, "/_api/import?type=documents&" + getCollectionUrlPart() + "&details=true", str, len, headerFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleResult(result);
|
handleResult(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImportHelper::handleResult (SimpleHttpResult* result) {
|
void ImportHelper::handleResult (SimpleHttpResult* result) {
|
||||||
if (! result) {
|
if (result == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,39 +508,51 @@ namespace triagens {
|
||||||
|
|
||||||
TRI_json_t* json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, r.str().c_str());
|
TRI_json_t* json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, r.str().c_str());
|
||||||
|
|
||||||
if (json) {
|
if (json != 0) {
|
||||||
// get the "error" flag. This returns a pointer, not a copy
|
// error details
|
||||||
TRI_json_t* error = TRI_LookupArrayJson(json, "error");
|
TRI_json_t const* details = TRI_LookupArrayJson(json, "details");
|
||||||
|
|
||||||
if (error) {
|
if (TRI_IsListJson(details)) {
|
||||||
if (error->_type == TRI_JSON_BOOLEAN && error->_value._boolean) {
|
const size_t n = details->_value._objects._length;
|
||||||
_hasError = true;
|
|
||||||
|
|
||||||
// get the error message. This returns a pointer, not a copy
|
for (size_t i = 0; i < n; ++i) {
|
||||||
TRI_json_t* errorMessage = TRI_LookupArrayJson(json, "errorMessage");
|
TRI_json_t const* detail = (TRI_json_t const*) TRI_AtVector(&details->_value._objects, i);
|
||||||
|
|
||||||
if (TRI_IsStringJson(errorMessage)) {
|
if (TRI_IsStringJson(detail)) {
|
||||||
_errorMessage = string(errorMessage->_value._string.data, errorMessage->_value._string.length);
|
LOG_WARNING("%s", detail->_value._string.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TRI_json_t* importResult;
|
// get the "error" flag. This returns a pointer, not a copy
|
||||||
|
TRI_json_t const* error = TRI_LookupArrayJson(json, "error");
|
||||||
|
|
||||||
// look up the "created" flag. This returns a pointer, not a copy
|
if (TRI_IsBooleanJson(error) &&
|
||||||
importResult= TRI_LookupArrayJson(json, "created");
|
error->_value._boolean) {
|
||||||
if (importResult) {
|
_hasError = true;
|
||||||
if (importResult->_type == TRI_JSON_NUMBER) {
|
|
||||||
_numberOk += (size_t) importResult->_value._number;
|
// get the error message. This returns a pointer, not a copy
|
||||||
|
TRI_json_t const* errorMessage = TRI_LookupArrayJson(json, "errorMessage");
|
||||||
|
|
||||||
|
if (TRI_IsStringJson(errorMessage)) {
|
||||||
|
_errorMessage = string(errorMessage->_value._string.data, errorMessage->_value._string.length - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TRI_json_t const* importResult;
|
||||||
|
|
||||||
|
// look up the "created" flag. This returns a pointer, not a copy
|
||||||
|
importResult = TRI_LookupArrayJson(json, "created");
|
||||||
|
|
||||||
|
if (TRI_IsNumberJson(importResult)) {
|
||||||
|
_numberOk += (size_t) importResult->_value._number;
|
||||||
|
}
|
||||||
|
|
||||||
// look up the "errors" flag. This returns a pointer, not a copy
|
// look up the "errors" flag. This returns a pointer, not a copy
|
||||||
importResult= TRI_LookupArrayJson(json, "errors");
|
importResult = TRI_LookupArrayJson(json, "errors");
|
||||||
if (importResult) {
|
|
||||||
if (importResult->_type == TRI_JSON_NUMBER) {
|
if (TRI_IsNumberJson(importResult)) {
|
||||||
_numberError += (size_t) importResult->_value._number;
|
_numberError += (size_t) importResult->_value._number;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// this will free the json struct will a sub-elements
|
// this will free the json struct will a sub-elements
|
||||||
|
|
|
@ -124,7 +124,7 @@ static bool CreateCollection = false;
|
||||||
/// @brief progress
|
/// @brief progress
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static bool Progress = false;
|
static bool Progress = true;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @}
|
/// @}
|
||||||
|
|
Loading…
Reference in New Issue