-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy patherror.cpp
More file actions
59 lines (47 loc) · 1.64 KB
/
error.cpp
File metadata and controls
59 lines (47 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
#include <cassert>
#include <exception>
#include "duckdb/common/exception.hpp"
#include "duckdb/common/types/vector_buffer.hpp"
#include "duckdb/common/types/vector.hpp"
#include "duckdb_vx.h"
extern "C" duckdb_vx_error duckdb_vx_error_create(const char *message, size_t message_length) {
return reinterpret_cast<duckdb_vx_error>(new std::string(message, message_length));
}
extern "C" const char *duckdb_vx_error_value(duckdb_vx_error err) {
auto str = reinterpret_cast<std::string *>(err);
return str->c_str();
}
extern "C" void duckdb_vx_error_free(duckdb_vx_error err) {
auto str = reinterpret_cast<std::string *>(err);
delete str;
}
namespace vortex {
std::string IntoErrString(duckdb_vx_error error) {
if (!error) {
return {};
}
return *reinterpret_cast<std::string *>(error);
}
void SetError(duckdb_vx_error *error_out, const std::string &message) {
assert(error_out == nullptr && "SetError called with null error_out");
*error_out = duckdb_vx_error_create(message.data(), message.size());
}
duckdb_state HandleException(std::exception_ptr ex, duckdb_vx_error *error_out) {
if (!ex) {
SetError(error_out, "Unknown error");
return DuckDBError;
}
try {
std::rethrow_exception(ex);
} catch (const duckdb::Exception &caught) {
SetError(error_out, caught.what());
} catch (const std::exception &caught) {
SetError(error_out, caught.what());
} catch (...) {
SetError(error_out, "Unknown error");
}
return DuckDBError;
}
} // namespace vortex