mirror of https://gitee.com/bigwinds/arangodb
better AQL error messages (#8503)
This commit is contained in:
parent
30796091f5
commit
0b14599b67
|
@ -304,9 +304,10 @@ void ModificationBlock::handleResult(int code, bool ignoreErrors,
|
|||
}
|
||||
|
||||
/// @brief process the result of a data-modification operation
|
||||
void ModificationBlock::handleBabyResult(std::unordered_map<int, size_t> const& errorCounter,
|
||||
void ModificationBlock::handleBabyResult(OperationResult const& opRes,
|
||||
size_t numBabies, bool ignoreAllErrors,
|
||||
bool ignoreDocumentNotFound) {
|
||||
std::unordered_map<int, size_t> const& errorCounter = opRes.countErrorCodes;
|
||||
if (errorCounter.empty()) {
|
||||
// update the success counter
|
||||
// All successful.
|
||||
|
@ -354,7 +355,28 @@ void ModificationBlock::handleBabyResult(std::unordered_map<int, size_t> const&
|
|||
TRI_ASSERT(first != errorCounter.end());
|
||||
}
|
||||
|
||||
THROW_ARANGO_EXCEPTION(first->first);
|
||||
auto code = first->first;
|
||||
|
||||
// check if we can find a specific error message
|
||||
try {
|
||||
if (opRes.slice().isArray()) {
|
||||
for (auto doc : VPackArrayIterator(opRes.slice())) {
|
||||
if (!doc.isObject() || !doc.hasKey("errorNum") || doc.get("errorNum").getInt() != code) {
|
||||
continue;
|
||||
}
|
||||
VPackSlice msg = doc.get("errorMessage");
|
||||
if (msg.isString()) {
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(code, msg.copyString());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
// fall-through to returning the generic error message, which better than
|
||||
// forwarding an internal error here
|
||||
}
|
||||
|
||||
// no specific error message found. now respond with a generic error message
|
||||
THROW_ARANGO_EXCEPTION(code);
|
||||
}
|
||||
|
||||
RemoveBlock::RemoveBlock(ExecutionEngine* engine, RemoveNode const* ep)
|
||||
|
@ -465,7 +487,7 @@ std::unique_ptr<AqlItemBlock> RemoveBlock::work() {
|
|||
|
||||
OperationResult opRes = _trx->remove(_collection->name(), toRemove, options);
|
||||
|
||||
handleBabyResult(opRes.countErrorCodes, static_cast<size_t>(toRemove.length()),
|
||||
handleBabyResult(opRes, static_cast<size_t>(toRemove.length()),
|
||||
ep->_options.ignoreErrors, ignoreDocumentNotFound);
|
||||
|
||||
if (opRes.fail()) {
|
||||
|
@ -592,8 +614,7 @@ std::unique_ptr<AqlItemBlock> InsertBlock::work() {
|
|||
|
||||
OperationResult opRes = _trx->insert(_collection->name(), toInsert, options);
|
||||
|
||||
handleBabyResult(opRes.countErrorCodes, static_cast<size_t>(toInsert.length()),
|
||||
ep->_options.ignoreErrors);
|
||||
handleBabyResult(opRes, static_cast<size_t>(toInsert.length()), ep->_options.ignoreErrors);
|
||||
|
||||
if (opRes.fail()) {
|
||||
THROW_ARANGO_EXCEPTION(opRes.result);
|
||||
|
@ -800,7 +821,7 @@ std::unique_ptr<AqlItemBlock> UpdateReplaceBlock::work() {
|
|||
// perform update/replace
|
||||
OperationResult opRes = apply(toUpdate, options);
|
||||
|
||||
handleBabyResult(opRes.countErrorCodes, static_cast<size_t>(toUpdate.length()),
|
||||
handleBabyResult(opRes, static_cast<size_t>(toUpdate.length()),
|
||||
ep->_options.ignoreErrors, ignoreDocumentNotFound);
|
||||
|
||||
if (opRes.fail()) {
|
||||
|
@ -1034,8 +1055,8 @@ std::unique_ptr<AqlItemBlock> UpsertBlock::work() {
|
|||
THROW_ARANGO_EXCEPTION(opResInsert.result);
|
||||
}
|
||||
|
||||
handleBabyResult(opResInsert.countErrorCodes,
|
||||
static_cast<size_t>(toInsert.length()), ep->_options.ignoreErrors);
|
||||
handleBabyResult(opResInsert, static_cast<size_t>(toInsert.length()),
|
||||
ep->_options.ignoreErrors);
|
||||
|
||||
resultListInsert = opResInsert.slice();
|
||||
if (!resultListInsert.isArray()) {
|
||||
|
@ -1057,8 +1078,8 @@ std::unique_ptr<AqlItemBlock> UpsertBlock::work() {
|
|||
THROW_ARANGO_EXCEPTION(opResUpdate.result);
|
||||
}
|
||||
|
||||
handleBabyResult(opResUpdate.countErrorCodes,
|
||||
static_cast<size_t>(toUpdate.length()), ep->_options.ignoreErrors);
|
||||
handleBabyResult(opResUpdate, static_cast<size_t>(toUpdate.length()),
|
||||
ep->_options.ignoreErrors);
|
||||
|
||||
resultListUpdate = opResUpdate.slice();
|
||||
if (!resultListUpdate.isArray()) {
|
||||
|
|
|
@ -83,7 +83,7 @@ class ModificationBlock : public ExecutionBlock {
|
|||
/// @brief process the result of a data-modification operation
|
||||
void handleResult(int, bool, std::string const* errorMessage = nullptr);
|
||||
|
||||
void handleBabyResult(std::unordered_map<int, size_t> const&, size_t,
|
||||
void handleBabyResult(OperationResult const&, size_t,
|
||||
bool ignoreAllErrors, bool ignoreDocumentNotFound = false);
|
||||
|
||||
/// @brief determine the number of rows in a vector of blocks
|
||||
|
|
Loading…
Reference in New Issue