8000 Feature/error messages as string views by goedderz · Pull Request #13455 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Feature/error messages as string views #13455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 66 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
3e30055
Made Result contain only an optional pointer to an error
goedderz Jan 21, 2021
fd78e02
Fixed compile error
goedderz Jan 21, 2021
df2e43c
Avoid no-error allocations
goedderz Jan 21, 2021
d447876
WIP
goedderz Jan 25, 2021
4d8d9b1
WIP
goedderz Jan 25, 2021
ab77f45
Added concatT and joinT to StringUtils
goedderz Jan 25, 2021
331fad5
Fixed tests
goedderz Jan 25, 2021
bfc7901
Merge branch 'feature/string-utils-concat-join' of github.com:arangod…
goedderz Jan 25, 2021
699a5dc
Changed namespace from impl to detail
goedderz Jan 25, 2021
8aa96ae
Assert capacity
goedderz Jan 25, 2021
b0e1b0c
Fixed compile errors
goedderz Jan 25, 2021
83bb4f8
Return a string_view in Result::errorMessage
goedderz Jan 25, 2021
c2435bc
Removed erroneous line
goedderz Jan 25, 2021
6949f89
Merge branch 'feature/refactor-error-message-string-view' of github.c…
goedderz Jan 25, 2021
0fed08d
Fixed some compile errors
goedderz Jan 26, 2021
d91cfb5
Some minor changes
goedderz Jan 26, 2021
6eb6ee1
Merge branch 'feature/refactor-error-message-string-view' of github.c…
goedderz Jan 26, 2021
1956b21
Update lib/Basics/ResultT.h
goedderz Jan 26, 2021
f5de874
Merge bra 8000 nch 'feature/refactor-error-message-string-view' of github.c…
goedderz Jan 26, 2021
84511fb
Fixed Mac compile error
goedderz Jan 26, 2021
eaacdc0
Merge branch 'feature/string-utils-concat-join' of github.com:arangod…
goedderz Jan 26, 2021
d988cf8
Merge branch 'feature/refactor-error-message-string-view' of github.c…
goedderz Jan 26, 2021
6d83aeb
Update lib/Basics/Result.h
goedderz Jan 27, 2021
937877d
Added errorMessage move overloads
goedderz Jan 27, 2021
4d49f20
Added noexcept where mentioned in reviews
goedderz Jan 27, 2021
0e098b2
Be consistent.
goedderz Jan 27, 2021
9c209b3
Merge branch 'devel' of github.com:arangodb/arangodb into feature/sma…
goedderz Jan 27, 2021
95e21c9
Make TRI_errno_string return a string_view
goedderz Jan 27, 2021
9e25112
Removed superfluous lines
goedderz Jan 27, 2021
2e6b197
Merge branch 'feature/small-result-with-external-error' of github.com…
goedderz Jan 27, 2021
6b15b7e
Fixed compile errors due to previous change
goedderz Jan 27, 2021
bc3c0ef
Merge branch 'devel' of github.com:arangodb/arangodb into feature/sma…
goedderz Jan 27, 2021
27fb946
Fixed merge conflict
goedderz Jan 27, 2021
0433a27
Minor changes
goedderz Jan 27, 2021
0fa6aa1
Added some assertions
goedderz Jan 28, 2021
76f2312
Pass conflictingDocumentKey separately, no longer in a Result's error…
goedderz Jan 28, 2021
99d1190
Merge branch 'feature/small-result-with-external-error' of github.com…
goedderz Jan 28, 2021
690c2d7
Fixed prior commit
goedderz Jan 28, 2021
f816181
Fix compile error
goedderz Jan 29, 2021
68be618
Merge branch 'feature/small-result-with-external-error' of github.com…
goedderz Jan 29, 2021
a6e7b67
Fixed assertion
goedderz Jan 29, 2021
943bf3e
Fix
goedderz Feb 1, 2021
e928f04
Only return conflicting key when it's meaningful, to soothe an assertion
goedderz Feb 1, 2021
0d78b83
Reformat
goedderz Feb 1, 2021
ef30942
Added a comment
goedderz Feb 1, 2021
a29e7bd
Addressed review comments
goedderz Feb 1, 2021
054cd6d
Merge branch 'feature/small-result-with-external-error' of github.com…
goedderz Feb 1, 2021
8d8bd19
Merge commit '0737c305c536043a3cde5916957dd2714836d25f' into feature/…
goedderz Feb 2, 2021
6fe7d1b
Merge branch 'devel' of github.com:arangodb/arangodb into feature/err…
goedderz Feb 2, 2021
3900256
Fix va args call in macro
goedderz Feb 3, 2021
9c4335f
autoformat
goedderz Feb 3, 2021
29239a0
Try not to rely on error messages being null-terminated as much as po…
goedderz Feb 3, 2021
6759548
Removed unused parts in exitcodes
goedderz Feb 3, 2021
5b2e94f
Try to fix conversion error on windows
goedderz Feb 3, 2021
0161341
Reverted two changes, fixed a compile error, fixed an off-by-one
goedderz Feb 4, 2021
61b16ff
Added a comment
goedderz Feb 4, 2021
d83d7b7
Merge branch 'devel' of github.com:arangodb/arangodb into feature/err…
goedderz Feb 8, 2021
b4f9613
Adressed some review comments
goedderz Feb 8, 2021
c8021d0
Passed some more errors as string_views
goedderz Feb 8, 2021
4dfcda5
Merge branch 'devel' of github.com:arangodb/arangodb into feature/err…
goedderz Feb 10, 2021
62f8892
Removed merge conflict marker
goedderz Feb 10, 2021
c768295
Fixed merge conflicts
goedderz Feb 10, 2021
baf963f
Fixed erroneous argument to snprintf
goedderz Feb 10, 2021
7463f85
Merge branch 'devel' of github.com:arangodb/arangodb into feature/err…
goedderz Feb 11, 2021
55dd841
Fixed merge conflict
goedderz Feb 11, 2021
72b9738
Removed voc-errors.cpp
goedderz Feb 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,6 @@ if (USE_MAINTAINER_MODE)

set(ERROR_FILES
lib/Basics/voc-errors.h
lib/Basics/voc-errors.cpp
lib/Basics/error-registry.h
js/common/bootstrap/errors.js
)
Expand Down
9 changes: 5 additions & 4 deletions arangod/Aql/Ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

using namespace arangodb;
using namespace arangodb::aql;
namespace StringUtils = arangodb::basics::StringUtils;

namespace {

Expand Down Expand Up @@ -3686,10 +3687,10 @@ AstNode* Ast::optimizeFor(AstNode* node) {
// right-hand operand to FOR statement is no array
THROW_ARANGO_EXCEPTION_MESSAGE(
TRI_ERROR_QUERY_ARRAY_EXPECTED,
std::string("collection or ") + TRI_errno_string(TRI_ERROR_QUERY_ARRAY_EXPECTED) +
std::string(" as operand to FOR loop; you specified type '") +
expression->getValueTypeString() + std::string("' with content '") +
expression->toString() + std::string("'"));
StringUtils::concatT(& 23D3 quot;collection or ", TRI_errno_string(TRI_ERROR_QUERY_ARRAY_EXPECTED),
" as operand to FOR loop; you specified type '",
expression->getValueTypeString(),
"' with content '", expression->toString(), "'"));
}

// no real optimizations will be done here
Expand Down
10 changes: 6 additions & 4 deletions arangod/Aql/EnumerateListExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,20 @@
#include "Aql/SingleRowFetcher.h"
#include "Aql/Stats.h"
#include "Basics/Exceptions.h"
#include "Basics/StringUtils.h"

using namespace arangodb;
using namespace arangodb::aql;
using namespace arangodb::basics;

namespace {
void throwArrayExpectedException(AqlValue const& value) {
THROW_ARANGO_EXCEPTION_MESSAGE(
TRI_ERROR_QUERY_ARRAY_EXPECTED,
std::string("collection or ") + TRI_errno_string(TRI_ERROR_QUERY_ARRAY_EXPECTED) +
std::string(
" as operand to FOR loop; you provided a value of type '") +
value.getTypeString() + std::string("'"));
StringUtils::concatT(
"collection or ", TRI_errno_string(TRI_ERROR_QUERY_ARRAY_EXPECTED),
" as operand to FOR loop; you provided a value of type '",
value.getTypeString(), "'"));
}
} // namespace

Expand Down
13 changes: 7 additions & 6 deletions arangod/Aql/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,21 @@ QueryResult Parser::parseWithDetails() {

/// @brief register a parse error, position is specified as line / column
void Parser::registerParseError(ErrorCode errorCode, char const* format,
char const* data, int line, int column) {
std::string_view data, int line, int column) {
char buffer[512];
// make sure the buffer is always initialized
buffer[0] = '\0';
buffer[sizeof(buffer) - 1] = '\0';

snprintf(buffer, sizeof(buffer) - 1, format, data);
snprintf(buffer, sizeof(buffer) - 1, format, data.data());

return registerParseError(errorCode, buffer, line, column);
}

/// @brief register a parse error, position is specified as line / column
void Parser::registerParseError(ErrorCode errorCode, char const* data, int line, int column) {
void Parser::registerParseError(ErrorCode errorCode, std::string_view data, int line, int column) {
TRI_ASSERT(errorCode != TRI_ERROR_NO_ERROR);
TRI_ASSERT(data != nullptr);
TRI_ASSERT(data.data() != nullptr);

// extract the query string part where the error happened
std::string const region(queryString().extractRegion(line, column));
Expand All @@ -172,11 +172,12 @@ void Parser::registerParseError(ErrorCode errorCode, char const* data, int line,
errorMessage << '^' << '^' << std::endl;
}

_query.warnings().registerError(errorCode, errorMessage.str().c_str());
_query.warnings().registerError(errorCode, errorMessage.str());
}

/// @brief register a warning
void Parser::registerWarning(ErrorCode errorCode, char const* data, int line, int column) {
void Parser::registerWarning(ErrorCode errorCode, std::string_view data,
[[maybe_unused]] int line, [[maybe_unused]] int column) {
// ignore line and column for now
_query.warnings().registerWarning(errorCode, data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is data null-terminated?

}
Expand Down
6 changes: 3 additions & 3 deletions arangod/Aql/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ class Parser {

/// @brief register a parse error, position is specified as line / column
void registerParseError(ErrorCode errorCode, char const* format,
char const* data, int line, int column);
std::string_view data, int line, int column);

/// @brief register a parse error, position is specified as line / column
void registerParseError(ErrorCode errorCode, char const* data, int line, int column);
void registerParseError(ErrorCode errorCode, std::string_view data, int line, int column);

/// @brief register a warning
void registerWarning(ErrorCode errorCode, char const* data, int line, int column);
void registerWarning(ErrorCode errorCode, std::string_view data, int line, int column);

/// @brief push an AstNode array element on top of the stack
/// the array must be removed from the stack via popArray
Expand Down
42 changes: 25 additions & 17 deletions arangod/Aql/Query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@

using namespace arangodb;
using namespace arangodb::aql;
using namespace arangodb::basics;

/// @brief internal constructor, Used to construct a full query or a ClusterQuery
Query::Query(std::shared_ptr<transaction::Context> const& ctx,
Expand Down Expand Up @@ -535,18 +536,20 @@ ExecutionState Query::execute(QueryResult& queryResult) {
QueryExecutionState::toStringWithPrefix(_execState)));
cleanupPlanAndEngine(ex.code(), /*sync*/true);
} catch (std::bad_alloc const&) {
queryResult.reset(Result(TRI_ERROR_OUT_OF_MEMORY,
TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY) +
QueryExecutionState::toStringWithPrefix(_execState)));
queryResult.reset(
Result(TRI_ERROR_OUT_OF_MEMORY,
StringUtils::concatT(TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY),
QueryExecutionState::toStringWithPrefix(_execState))));
cleanupPlanAndEngine(TRI_ERROR_OUT_OF_MEMORY, /*sync*/true);
} catch (std::exception const& ex) {
queryResult.reset(Result(TRI_ERROR_INTERNAL,
ex.what() + QueryExecutionState::toStringWithPrefix(_execState)));
cleanupPlanAndEngine(TRI_ERROR_INTERNAL, /*sync*/true);
} catch (...) {
queryResult.reset(Result(TRI_ERROR_INTERNAL,
TRI_errno_string(TRI_ERROR_INTERNAL) +
QueryExecutionState::toStringWithPrefix(_execState)));
queryResult.reset(
Result(TRI_ERROR_INTERNAL,
StringUtils::concatT(TRI_errno_string(TRI_ERROR_INTERNAL),
QueryExecutionState::toStringWithPrefix(_execState))));
cleanupPlanAndEngine(TRI_ERROR_INTERNAL, /*sync*/true);
}

Expand Down Expand Up @@ -756,19 +759,21 @@ QueryResultV8 Query::executeV8(v8::Isolate* isolate) {
QueryExecutionState::toStringWithPrefix(_execState)));
cleanupPlanAndEngine(ex.code(), /*sync*/true);
} catch (std::bad_alloc const&) {
queryResult.reset(Result(TRI_ERROR_OUT_OF_MEMORY,
TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY) +
QueryExecutionState::toStringWithPrefix(_execState)));
queryResult.reset(
Result(TRI_ERROR_OUT_OF_MEMORY,
StringUtils::concatT(TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY),
QueryExecutionState::toStringWithPrefix(_execState))));
cleanupPlanAndEngine(TRI_ERROR_OUT_OF_MEMORY, /*sync*/true);
} catch (std::exception const& ex) {
queryResult.reset(Result(TRI_ERROR_INTERNAL,
ex.what() + QueryExecutionState::toStringWithPrefix(_execState)));
cleanupPlanAndEngine(TRI_ERROR_INTERNAL, /*sync*/true);
} catch (...) {
queryResult.reset(Result(TRI_ERROR_INTERNAL,
TRI_errno_string(TRI_ERROR_INTERNAL) +
QueryExecutionState::toStringWithPrefix(_execState)));
cleanupPlanAndEngine(TRI_ERROR_INTERNAL, /*sync*/true);
queryResult.reset(
Result(TRI_ERROR_INTERNAL,
StringUtils::concatT(TRI_errno_string(TRI_ERROR_INTERNAL),
QueryExecutionState::toStringWithPrefix(_execState))));
cleanupPlanAndEngine(TRI_ERROR_INTERNAL, /*sync*/ true);
}

return queryResult;
Expand Down Expand Up @@ -942,13 +947,16 @@ QueryResult Query::explain() {
} catch (arangodb::basics::Exception const& ex) {
result.reset(Result(ex.code(), ex.message() + QueryExecutionState::toStringWithPrefix(_execState)));
} catch (std::bad_alloc const&) {
result.reset(Result(TRI_ERROR_OUT_OF_MEMORY,
TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY) +
QueryExecutionState::toStringWithPrefix(_execState)));
result.reset(
Result(TRI_ERROR_OUT_OF_MEMORY,
StringUtils::concatT(TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY),
QueryExecutionState::toStringWithPrefix(_execState))));
} catch (std::exception const& ex) {
result.reset(Result(TRI_ERROR_INTERNAL, ex.what() + QueryExecutionState::toStringWithPrefix(_execState)));
} catch (...) {
result.reset(Result(TRI_ERROR_INTERNAL, TRI_errno_string(TRI_ERROR_INTERNAL) + QueryExecutionState::toStringWithPrefix(_execState)));
result.reset(Result(TRI_ERROR_INTERNAL,
StringUtils::concatT(TRI_errno_string(TRI_ERROR_INTERNAL),
QueryExecutionState::toStringWithPrefix(_execState))));
}

// will be returned in success or failure case
Expand Down
23 changes: 14 additions & 9 deletions arangod/Aql/QueryCursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "Aql/Query.h"
#include "Aql/QueryRegistry.h"
#include "Basics/ScopeGuard.h"
#include "Basics/StringUtils.h"
#include "Logger/LogMacros.h"
#include "RestServer/QueryRegistryFeature.h"
#include "StorageEngine/TransactionState.h"
Expand All @@ -46,6 +47,7 @@

using namespace arangodb;
using namespace arangodb::aql;
using namespace arangodb::basics;

QueryResultCursor::QueryResultCursor(TRI_vocbase_t& vocbase, aql::QueryResult&& result,
size_t batchSize, double ttl, bool hasCount)
Expand Down Expand Up @@ -233,8 +235,9 @@ std::pair<ExecutionState, Result> QueryStreamCursor::dump(VPackBuilder& builder)
this->setDeleted();
return {ExecutionState::DONE,
Result(TRI_ERROR_OUT_OF_MEMORY,
TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY) +
QueryExecutionState::toStringWithPrefix(_query->state()))};
StringUtils::concatT(TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY),
QueryExecutionState::toStringWithPrefix(
_query->state())))};
} catch (std::exception const& ex) {
this->setDeleted();
return {ExecutionState::DONE,
Expand All @@ -244,8 +247,8 @@ std::pair<ExecutionState, Result> QueryStreamCursor::dump(VPackBuilder& builder)
this->setDeleted();
return {ExecutionState::DONE,
Result(TRI_ERROR_INTERNAL,
TRI_errno_string(TRI_ERROR_INTERNAL) +
QueryExecutionState::toStringWithPrefix(_query->state()))};
StringUtils::concatT(TRI_errno_string(TRI_ERROR_INTERNAL),
QueryExecutionState::toStringWithPrefix(_query->state())))};
}
}

Expand Down Expand Up @@ -287,19 +290,21 @@ Result QueryStreamCursor::dumpSync(VPackBuilder& builder) {
} catch (std::bad_alloc const&) {
this->setDeleted();
return Result(TRI_ERROR_OUT_OF_MEMORY,
TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY) +
QueryExecutionState::toStringWithPrefix(_query->state()));
StringUtils::concatT(TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY),
QueryExecutionState::toStringWithPrefix(
_query->state())));
} catch (std::exception const& ex) {
this->setDeleted();
return Result(TRI_ERROR_INTERNAL,
ex.what() + QueryExecutionState::toStringWithPrefix(_query->state()));
} catch (...) {
this->setDeleted();
return Result(TRI_ERROR_INTERNAL,
TRI_errno_string(TRI_ERROR_INTERNAL) +
QueryExecutionState::toStringWithPrefix(_query->state()));
StringUtils::concatT(TRI_errno_string(TRI_ERROR_INTERNAL),
QueryExecutionState::toStringWithPrefix(
_query->state())));
}

return Result();
}

Expand Down
14 changes: 5 additions & 9 deletions arangod/Aql/QueryWarnings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,25 @@ QueryWarnings::QueryWarnings()

/// @brief register an error
/// this also makes the query abort
void QueryWarnings::registerError(ErrorCode code, char const* details) {
void QueryWarnings::registerError(ErrorCode code, std::string_view details) {
TRI_ASSERT(code != TRI_ERROR_NO_ERROR);

if (details == nullptr) {
if (details.data() == nullptr) {
THROW_ARANGO_EXCEPTION(code);
}

THROW_ARANGO_EXCEPTION_MESSAGE(code, details);
}

void QueryWarnings::registerWarning(ErrorCode code, std::string const& details) {
registerWarning(code, details.c_str());
}

/// @brief register a warning
void QueryWarnings::registerWarning(ErrorCode code, char const* details) {
void QueryWarnings::registerWarning(ErrorCode code, std::string_view details) {
TRI_ASSERT(code != TRI_ERROR_NO_ERROR);

std::lock_guard<std::mutex> guard(_mutex);

if (_failOnWarning) {
// make an error from each warning if requested
if (details == nullptr) {
if (details.data() == nullptr) {
THROW_ARANGO_EXCEPTION(code);
}
THROW_ARANGO_EXCEPTION_MESSAGE(code, details);
Expand All @@ -71,7 +67,7 @@ void QueryWarnings::registerWarning(ErrorCode code, char const* details) {
return;
}

if (details == nullptr) {
if (details.data() == nullptr) {
_list.emplace_back(code, TRI_errno_string(code));
} else {
_list.emplace_back(code, details);
Expand Down
8 changes: 2 additions & 6 deletions arangod/Aql/QueryWarnings.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,9 @@ class QueryWarnings final {

/// @brief register an error
/// this also makes the query abort
[[noreturn]] void registerError(ErrorCode code, char const* details = nullptr);

[[noreturn]] v D9B2 oid registerError(ErrorCode code, std::string_view details = {});
/// @brief register a warning
void registerWarning(ErrorCode code, char const* details = nullptr);

/// @brief register a warning (convenience overload)
void registerWarning(ErrorCode code, std::string const& details);
void registerWarning(ErrorCode code, std::string_view details = {});

void toVelocyPack(arangodb::velocypack::Builder& b) const;

Expand Down
4 changes: 2 additions & 2 deletions arangod/Aql/WindowNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ bool parameterToTimePoint(AqlValue const& value, QueryWarnings& warnings,
}
return true;
}*/
warnings.registerWarning(TRI_ERROR_QUERY_INVALID_DATE_VALUE, nullptr);
warnings.registerWarning(TRI_ERROR_QUERY_INVALID_DATE_VALUE);
return false;
}

Expand Down Expand Up @@ -232,7 +232,7 @@ WindowBounds::Row WindowBounds::calcRow(AqlValue const& input, QueryWarnings& w)
bool failed;
double val = input.toDouble(failed);
if (failed) {
w.registerWarning(TRI_ERROR_QUERY_INVALID_ARITHMETIC_VALUE, nullptr);
w.registerWarning(TRI_ERROR_QUERY_INVALID_ARITHMETIC_VALUE);
return {0, 0, 0, /*valid*/ false};
}

Expand Down
Loading
0