1 | //===----------------------------------------------------------------------===// |
2 | // DuckDB |
3 | // |
4 | // duckdb/parser/query_error_context.hpp |
5 | // |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #pragma once |
10 | |
11 | #include "duckdb/common/common.hpp" |
12 | #include "duckdb/common/vector.hpp" |
13 | #include "duckdb/common/exception_format_value.hpp" |
14 | #include "duckdb/common/optional_ptr.hpp" |
15 | |
16 | namespace duckdb { |
17 | class SQLStatement; |
18 | |
19 | class QueryErrorContext { |
20 | public: |
21 | explicit QueryErrorContext(optional_ptr<SQLStatement> statement_ = nullptr, |
22 | idx_t query_location_ = DConstants::INVALID_INDEX) |
23 | : statement(statement_), query_location(query_location_) { |
24 | } |
25 | |
26 | //! The query statement |
27 | optional_ptr<SQLStatement> statement; |
28 | //! The location in which the error should be thrown |
29 | idx_t query_location; |
30 | |
31 | public: |
32 | DUCKDB_API static string Format(const string &query, const string &error_message, int error_location); |
33 | |
34 | DUCKDB_API string FormatErrorRecursive(const string &msg, vector<ExceptionFormatValue> &values); |
35 | template <class T, typename... Args> |
36 | string FormatErrorRecursive(const string &msg, vector<ExceptionFormatValue> &values, T param, Args... params) { |
37 | values.push_back(ExceptionFormatValue::CreateFormatValue<T>(param)); |
38 | return FormatErrorRecursive(msg, values, params...); |
39 | } |
40 | |
41 | template <typename... Args> |
42 | string FormatError(const string &msg, Args... params) { |
43 | vector<ExceptionFormatValue> values; |
44 | return FormatErrorRecursive(msg, values, params...); |
45 | } |
46 | }; |
47 | |
48 | } // namespace duckdb |
49 | |