8000 Feature/error messages as string views (#13455) · tylde/arangodb@389342f · GitHub
[go: up one dir, main page]

Skip to content

Commit 389342f

Browse files
goedderzjsteemann
andauthored
Feature/error messages as string views (arangodb#13455)
Co-authored-by: Jan <jsteemann@users.noreply.github.com>
1 parent c0ce388 commit 389342f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1913
-2537
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,6 @@ if (USE_MAINTAINER_MODE)
12451245

12461246
set(ERROR_FILES
12471247
lib/Basics/voc-errors.h
1248-
lib/Basics/voc-errors.cpp
12491248
lib/Basics/error-registry.h
12501249
js/common/bootstrap/errors.js
12511250
)

arangod/Aql/Ast.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
using namespace arangodb;
5959
using namespace arangodb::aql;
60+
namespace StringUtils = arangodb::basics::StringUtils;
6061

6162
namespace {
6263

@@ -3686,10 +3687,10 @@ AstNode* Ast::optimizeFor(AstNode* node) {
36863687
// right-hand operand to FOR statement is no array
36873688
THROW_ARANGO_EXCEPTION_MESSAGE(
36883689
TRI_ERROR_QUERY_ARRAY_EXPECTED,
3689-
std::string("collection or ") + TRI_errno_string(TRI_ERROR_QUERY_ARRAY_EXPECTED) +
3690-
std::string(" as operand to FOR loop; you specified type '") +
3691-
expression->getValueTypeString() + std::string("' with content '") +
3692-
expression->toString() + std::string("'"));
3690+
StringUtils::concatT("collection or ", TRI_errno_string(TRI_ERROR_QUERY_ARRAY_EXPECTED),
3691+
" as operand to FOR loop; you specified type '",
3692+
expression->getValueTypeString(),
3693+
"' with content '", expression->toString(), "'"));
36933694
}
36943695

36953696
// no real optimizations will be done here

arangod/Aql/EnumerateListExecutor.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,20 @@
3535
#include "Aql/SingleRowFetcher.h"
3636
#include "Aql/Stats.h"
3737
#include "Basics/Exceptions.h"
38+
#include "Basics/StringUtils.h"
3839

3940
using namespace arangodb;
4041
using namespace arangodb::aql;
42+
using namespace arangodb::basics;
4143

4244
namespace {
4345
void throwArrayExpectedException(AqlValue const& value) {
4446
THROW_ARANGO_EXCEPTION_MESSAGE(
4547
TRI_ERROR_QUERY_ARRAY_EXPECTED,
46-
std::string("collection or ") + TRI_errno_string(TRI_ERROR_QUERY_ARRAY_EXPECTED) +
47-
std::string(
48-
" as operand to FOR loop; you provided a value of type '") +
49-
value.getTypeString() + std::string("'"));
48+
StringUtils::concatT(
49+
"collection or ", TRI_errno_string(TRI_ERROR_QUERY_ARRAY_EXPECTED),
50+
" as operand to FOR loop; you provided a value of type '",
51+
value.getTypeString(), "'"));
5052
}
5153
} // namespace
5254

arangod/Aql/Parser.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,21 @@ QueryResult Parser::parseWithDetails() {
133133

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

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

144144
return registerParseError(errorCode, buffer, line, column);
145145
}
146146

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

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

175-
_query.warnings().registerError(errorCode, errorMessage.str().c_str());
175+
_query.warnings().registerError(errorCode, errorMessage.str());
176176
}
177177

178178
/// @brief register a warning
179-
void Parser::registerWarning(ErrorCode errorCode, char const* data, int line, int column) {
179+
void Parser::registerWarning(ErrorCode errorCode, std::string_view data,
180+
[[maybe_unused]] int line, [[maybe_unused]] int column) {
180181
// ignore line and column for now
181182
_query.warnings().registerWarning(errorCode, data);
182183
}

arangod/Aql/Parser.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ class Parser {
103103

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

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

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

114114
/// @brief push an AstNode array element on top of the stack
115115
/// the array must be removed from the stack via popArray

arangod/Aql/Query.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878

7979
using namespace arangodb;
8080
using namespace arangodb::aql;
81+
using namespace arangodb::basics;
8182

8283
/// @brief internal constructor, Used to construct a full query or a ClusterQuery
8384
Query::Query(std::shared_ptr<transaction::Context> const& ctx,
@@ -535,18 +536,20 @@ ExecutionState Query::execute(QueryResult& queryResult) {
535536
QueryExecutionState::toStringWithPrefix(_execState)));
536537
cleanupPlanAndEngine(ex.code(), /*sync*/true);
537538
} catch (std::bad_alloc const&) {
538-
queryResult.reset(Result(TRI_ERROR_OUT_OF_MEMORY,
539-
TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY) +
540-
QueryExecutionState::toStringWithPrefix(_execState)));
539+
queryResult.reset(
540+
Result(TRI_ERROR_OUT_OF_MEMORY,
541+
StringUtils::concatT(TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY),
542+
QueryExecutionState::toStringWithPrefix(_execState))));
541543
cleanupPlanAndEngine(TRI_ERROR_OUT_OF_MEMORY, /*sync*/true);
542544
} catch (std::exception const& ex) {
543545
queryResult.reset(Result(TRI_ERROR_INTERNAL,
544546
ex.what() + QueryExecutionState::toStringWithPrefix(_execState)));
545547
cleanupPlanAndEngine(TRI_ERROR_INTERNAL, /*sync*/true);
546548
} catch (...) {
547-
queryResult.reset(Result(TRI_ERROR_INTERNAL,
548-
TRI_errno_string(TRI_ERROR_INTERNAL) +
549-
QueryExecutionState::toStringWithPrefix(_execState)));
549+
queryResult.reset(
550+
Result(TRI_ERROR_INTERNAL,
551+
StringUtils::concatT(TRI_errno_string(TRI_ERROR_INTERNAL),
552+
10000 QueryExecutionState::toStringWithPrefix(_execState))));
550553
cleanupPlanAndEngine(TRI_ERROR_INTERNAL, /*sync*/true);
551554
}
552555

@@ -756,19 +759,21 @@ QueryResultV8 Query::executeV8(v8::Isolate* isolate) {
756759
QueryExecutionState::toStringWithPrefix(_execState)));
757760
cleanupPlanAndEngine(ex.code(), /*sync*/true);
758761
} catch (std::bad_alloc const&) {
759-
queryResult.reset(Result(TRI_ERROR_OUT_OF_MEMORY,
760-
TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY) +
761-
QueryExecutionState::toStringWithPrefix(_execState)));
762+
queryResult.reset(
763+
Result(TRI_ERROR_OUT_OF_MEMORY,
764+
StringUtils::concatT(TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY),
765+
QueryExecutionState::toStringWithPrefix(_execState))));
762766
cleanupPlanAndEngine(TRI_ERROR_OUT_OF_MEMORY, /*sync*/true);
763767
} catch (std::exception const& ex) {
764768
queryResult.reset(Result(TRI_ERROR_INTERNAL,
765769
ex.what() + QueryExecutionState::toStringWithPrefix(_execState)));
766770
cleanupPlanAndEngine(TRI_ERROR_INTERNAL, /*sync*/true);
767771
} catch (...) {
768-
queryResult.reset(Result(TRI_ERROR_INTERNAL,
769-
TRI_errno_string(TRI_ERROR_INTERNAL) +
770-
QueryExecutionState::toStringWithPrefix(_execState)));
771-
cleanupPlanAndEngine(TRI_ERROR_INTERNAL, /*sync*/true);
772+
queryResult.reset(
773+
Result(TRI_ERROR_INTERNAL,
774+
StringUtils::concatT(TRI_errno_string(TRI_ERROR_INTERNAL),
775+
QueryExecutionState::toStringWithPrefix(_execState))));
776+
cleanupPlanAndEngine(TRI_ERROR_INTERNAL, /*sync*/ true);
772777
}
773778

774779
return queryResult;
@@ -942,13 +947,16 @@ QueryResult Query::explain() {
942947
} catch (arangodb::basics::Exception const& ex) {
943948
result.reset(Result(ex.code(), ex.message() + QueryExecutionState::toStringWithPrefix(_execState)));
944949
} catch (std::bad_alloc const&) {
945-
result.reset(Result(TRI_ERROR_OUT_OF_MEMORY,
946-
TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY) +
947-
QueryExecutionState::toStringWithPrefix(_execState)));
950+
result.reset(
951+
Result(TRI_ERROR_OUT_OF_MEMORY,
952+
StringUtils::concatT(TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY),
953+
QueryExecutionState::toStringWithPrefix(_execState))));
948954
} catch (std::exception const& ex) {
949955
result.reset(Result(TRI_ERROR_INTERNAL, ex.what() + QueryExecutionState::toStringWithPrefix(_execState)));
950956
} catch (...) {
951-
result.reset(Result(TRI_ERROR_INTERNAL, TRI_errno_string(TRI_ERROR_INTERNAL) + QueryExecutionState::toStringWithPrefix(_execState)));
957+
result.reset(Result(TRI_ERROR_INTERNAL,
958+
StringUtils::concatT(TRI_errno_string(TRI_ERROR_INTERNAL),
959+
QueryExecutionState::toStringWithPrefix(_execState))));
952960
}
953961

954962
// will be returned in success or failure case

arangod/Aql/QueryCursor.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "Aql/Query.h"
3131
#include "Aql/QueryRegistry.h"
3232
#include "Basics/ScopeGuard.h"
33+
#include "Basics/StringUtils.h"
3334
#include "Logger/LogMacros.h"
3435
#include "RestServer/QueryRegistryFeature.h"
3536
#include "StorageEngine/TransactionState.h"
@@ -46,6 +47,7 @@
4647

4748
using namespace arangodb;
4849
using namespace arangodb::aql;
50+
using namespace arangodb::basics;
4951

5052
QueryResultCursor::QueryResultCursor(TRI_vocbase_t& vocbase, aql::QueryResult&& result,
5153
size_t batchSize, double ttl, bool hasCount)
@@ -233,8 +235,9 @@ std::pair<ExecutionState, Result> QueryStreamCursor::dump(VPackBuilder& builder)
233235
this->setDeleted();
234236
return {ExecutionState::DONE,
235237
Result(TRI_ERROR_OUT_OF_MEMORY,
236-
TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY) +
237-
QueryExecutionState::toStringWithPrefix(_query->state()))};
238+
StringUtils::concatT(TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY),
239+
QueryExecutionState::toStringWithPrefix(
240+
_query->state())))};
238241
} catch (std::exception const& ex) {
239242
this->setDeleted();
240243
return {ExecutionState::DONE,
@@ -244,8 +247,8 @@ std::pair<ExecutionState, Result> QueryStreamCursor::dump(VPackBuilder& builder)
244247
this->setDeleted();
245248
return {ExecutionState::DONE,
246249
Result(TRI_ERROR_INTERNAL,
247-
TRI_errno_string(TRI_ERROR_INTERNAL) +
248-
QueryExecutionState::toStringWithPrefix(_query->state()))};
250+
StringUtils::concatT(TRI_errno_string(TRI_ERROR_INTERNAL),
251+
QueryExecutionState::toStringWithPrefix(_query->state())))};
249252
}
250253
}
251254

@@ -287,19 +290,21 @@ Result QueryStreamCursor::dumpSync(VPackBuilder& builder) {
287290
} catch (std::bad_alloc const&) {
288291
this->setDeleted();
289292
return Result(TRI_ERROR_OUT_OF_MEMORY,
290-
TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY) +
291-
QueryExecutionState::toStringWithPrefix(_query->state()));
293+
StringUtils::concatT(TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY),
294+
QueryExecutionState::toStringWithPrefix(
295+
_query->state())));
292296
} catch (std::exception const& ex) {
293297
this->setDeleted();
294298
return Result(TRI_ERROR_INTERNAL,
295299
ex.what() + QueryExecutionState::toStringWithPrefix(_query->state()));
296300
} catch (...) {
297301
this->setDeleted();
298302
return Result(TRI_ERROR_INTERNAL,
299-
TRI_errno_string(TRI_ERROR_INTERNAL) +
300-
QueryExecutionState::toStringWithPrefix(_query->state()));
303+
StringUtils::concatT(TRI_errno_string(TRI_ERROR_INTERNAL),
304+
QueryExecutionState::toStringWithPrefix(
305+
_query->state())));
301306
}
302-
307+
303308
return Result();
304309
}
305310

arangod/Aql/QueryWarnings.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,25 @@ QueryWarnings::QueryWarnings()
3939

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

45-
if (details == nullptr) {
45+
if (details.data() == nullptr) {
4646
THROW_ARANGO_EXCEPTION(code);
4747
}
4848

4949
THROW_ARANGO_EXCEPTION_MESSAGE(code, details);
5050
}
5151

52-
void QueryWarnings::registerWarning(ErrorCode code, std::string const& details) {
53-
registerWarning(code, details.c_str());
54-
}
55-
5652
/// @brief register a warning
57-
void QueryWarnings::registerWarning(ErrorCode code, char const* details) {
53+
void QueryWarnings::registerWarning(ErrorCode code, std::string_view details) {
5854
TRI_ASSERT(code != TRI_ERROR_NO_ERROR);
5955

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

6258
if (_failOnWarning) {
6359
// make an error from each warning if requested
64-
if (details == nullptr) {
60+
if (details.data() == nullptr) {
6561
THROW_ARANGO_EXCEPTION(code);
6662
}
6763
THROW_ARANGO_EXCEPTION_MESSAGE(code, details);
@@ -71,7 +67,7 @@ void QueryWarnings::registerWarning(ErrorCode code, char const* details) {
7167
return;
7268
}
7369

74-
if (details == nullptr) {
70+
if (details.data() == nullptr) {
7571
_list.emplace_back(code, TRI_errno_string(code));
7672
} else {
7773
_list.emplace_back(code, details);

arangod/Aql/QueryWarnings.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,9 @@ class QueryWarnings final {
4949

5050
/// @brief register an error
5151
/// this also makes the query abort
52-
[[noreturn]] void registerError(ErrorCode code, char const* details = nullptr);
53-
52+
[[noreturn]] void registerError(ErrorCode code, std::string_view details = {});
5453
/// @brief register a warning
55-
void registerWarning(ErrorCode code, char const* details = nullptr);
56-
57-
/// @brief register a warning (convenience overload)
58-
void registerWarning(ErrorCode code, std::string const& details);
54+
void registerWarning(ErrorCode code, std::string_view details = {});
5955

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

arangod/Aql/WindowNode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ bool parameterToTimePoint(AqlValue const& value, QueryWarnings& warnings,
169169
}
170170
return true;
171171
}*/
172-
warnings.registerWarning(TRI_ERROR_QUERY_INVALID_DATE_VALUE, nullptr);
172+
warnings.registerWarning(TRI_ERROR_QUERY_INVALID_DATE_VALUE);
173173
return false;
174174
}
175175

@@ -232,7 +232,7 @@ WindowBounds::Row WindowBounds::calcRow(AqlValue const& input, QueryWarnings& w)
232232
bool failed;
233233
double val = input.toDouble(failed);
234234
if (failed) {
235-
w.registerWarning(TRI_ERROR_QUERY_INVALID_ARITHMETIC_VALUE, nullptr);
235+
w.registerWarning(TRI_ERROR_QUERY_INVALID_ARITHMETIC_VALUE);
236236
return {0, 0, 0, /*valid*/ false};
237237
}
238238

0 commit comments

Comments
 (0)
0