• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-core / github_pull_request_312964

19 Feb 2025 07:31PM UTC coverage: 90.814% (-0.3%) from 91.119%
github_pull_request_312964

Pull #8071

Evergreen

web-flow
Bump serialize-javascript and mocha

Bumps [serialize-javascript](https://github.com/yahoo/serialize-javascript) to 6.0.2 and updates ancestor dependency [mocha](https://github.com/mochajs/mocha). These dependencies need to be updated together.


Updates `serialize-javascript` from 6.0.0 to 6.0.2
- [Release notes](https://github.com/yahoo/serialize-javascript/releases)
- [Commits](https://github.com/yahoo/serialize-javascript/compare/v6.0.0...v6.0.2)

Updates `mocha` from 10.2.0 to 10.8.2
- [Release notes](https://github.com/mochajs/mocha/releases)
- [Changelog](https://github.com/mochajs/mocha/blob/main/CHANGELOG.md)
- [Commits](https://github.com/mochajs/mocha/compare/v10.2.0...v10.8.2)

---
updated-dependencies:
- dependency-name: serialize-javascript
  dependency-type: indirect
- dependency-name: mocha
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #8071: Bump serialize-javascript and mocha

96552 of 179126 branches covered (53.9%)

212672 of 234185 relevant lines covered (90.81%)

3115802.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.05
/src/realm/object-store/c_api/error.cpp
1
#include <realm/object-store/c_api/error.hpp>
2
#include <realm/object-store/c_api/util.hpp>
3
#include <realm/parser/query_parser.hpp>
4

5
#if REALM_PLATFORM_APPLE && !defined(RLM_NO_THREAD_LOCAL)
6
#define RLM_NO_THREAD_LOCAL
7
#endif
8

9
#if defined(RLM_NO_THREAD_LOCAL)
10
#include <pthread.h>
11
#endif
12

13
namespace realm::c_api {
14

15
ErrorStorage::ErrorStorage(std::exception_ptr ptr) noexcept
16
    : m_err(none)
1✔
17
    , m_message_buf()
1✔
18
    , m_user_code_error(nullptr)
1✔
19
{
1✔
20
    assign(std::move(ptr));
1✔
21
}
1✔
22

23
ErrorStorage::ErrorStorage(const ErrorStorage& other)
24
    : m_err(other.m_err)
3✔
25
    , m_message_buf(other.m_message_buf)
3✔
26
    , m_user_code_error(other.m_user_code_error)
3✔
27
{
3✔
28
    if (m_err) {
3✔
29
        m_err->message = m_message_buf.c_str();
3✔
30
    }
3✔
31
}
3✔
32

33
ErrorStorage& ErrorStorage::operator=(const ErrorStorage& other)
34
{
×
35
    m_err = other.m_err;
×
36
    m_message_buf = other.m_message_buf;
×
37
    m_user_code_error = other.m_user_code_error;
×
38
    if (m_err) {
×
39
        m_err->message = m_message_buf.c_str();
×
40
    }
×
41
    return *this;
×
42
}
×
43

44
ErrorStorage::ErrorStorage(ErrorStorage&& other)
45
    : m_err(std::move(other.m_err))
×
46
    , m_message_buf(std::move(other.m_message_buf))
×
47
    , m_user_code_error(std::move(other.m_user_code_error))
×
48
{
×
49
    if (m_err) {
×
50
        m_err->message = m_message_buf.c_str();
×
51
    }
×
52
    other.m_err.reset();
×
53
}
×
54

55
ErrorStorage& ErrorStorage::operator=(ErrorStorage&& other)
56
{
×
57
    m_err = std::move(other.m_err);
×
58
    m_message_buf = std::move(other.m_message_buf);
×
59
    m_user_code_error = std::move(other.m_user_code_error);
×
60
    if (m_err) {
×
61
        m_err->message = m_message_buf.c_str();
×
62
    }
×
63
    other.m_err.reset();
×
64
    return *this;
×
65
}
×
66

67
bool ErrorStorage::operator==(const ErrorStorage& other) const noexcept
68
{
1✔
69
    if (bool(m_err) != bool(other.m_err)) {
1✔
70
        return false;
×
71
    }
×
72
    else if (!m_err && !other.m_err) {
1!
73
        return true;
×
74
    }
×
75
    return m_err->error == other.m_err->error && m_message_buf == other.m_message_buf;
1✔
76
}
1✔
77

78
void ErrorStorage::assign(std::exception_ptr eptr) noexcept
79
{
101✔
80
    if (!eptr) {
101✔
81
        clear();
×
82
        return;
×
83
    }
×
84

85
    m_err.emplace();
101✔
86
    m_err->user_code_error = nullptr;
101✔
87
    m_err->path = nullptr;
101✔
88
    auto populate_error = [&](const std::exception& ex, ErrorCodes::Error error_code) {
101✔
89
        m_err->error = realm_errno_e(error_code);
101✔
90
        m_err->categories = ErrorCodes::error_categories(error_code).value();
101✔
91
        try {
101✔
92
            m_message_buf = ex.what();
101✔
93
            m_err->message = m_message_buf.c_str();
101✔
94
        }
101✔
95
        catch (const std::bad_alloc&) {
101✔
96
            // If we are unable to build the new error because we ran out of memory we should propagate the OOM
97
            // condition and leaf the m_message_buf as it was.
98
            m_err->error = RLM_ERR_OUT_OF_MEMORY;
×
99
            m_err->message = "Out of memory while creating realm_error_t";
×
100
        }
×
101
    };
101✔
102

103
    try {
101✔
104
        std::rethrow_exception(eptr);
101✔
105
    }
101✔
106

107
    // Core exceptions:
108
    catch (const Exception& ex) {
101✔
109
        populate_error(ex, ex.code());
97✔
110
        if (ex.code() == ErrorCodes::CallbackFailed) {
97✔
111
            m_err->user_code_error = static_cast<const CallbackFailed&>(ex).user_code_error;
3✔
112
        }
3✔
113
        if (ErrorCodes::error_categories(ex.code()).test(ErrorCategory::file_access)) {
97✔
114
            auto& file_access_error = static_cast<const FileAccessError&>(ex);
3✔
115
            m_path_buf = file_access_error.get_path();
3✔
116
            m_err->path = m_path_buf.c_str();
3✔
117
        }
3✔
118
    }
97✔
119

120
    // Generic exceptions:
121
    catch (const std::invalid_argument& ex) {
101✔
122
        populate_error(ex, ErrorCodes::InvalidArgument);
×
123
    }
×
124
    catch (const std::out_of_range& ex) {
101✔
125
        populate_error(ex, ErrorCodes::OutOfBounds);
×
126
    }
×
127
    catch (const std::logic_error& ex) {
101✔
128
        populate_error(ex, ErrorCodes::LogicError);
×
129
    }
×
130
    catch (const std::runtime_error& ex) {
101✔
131
        populate_error(ex, ErrorCodes::RuntimeError);
4✔
132
    }
4✔
133
    catch (const std::bad_alloc& ex) {
101✔
134
        populate_error(ex, ErrorCodes::OutOfMemory);
×
135
    }
×
136
    catch (const std::exception& ex) {
101✔
137
        populate_error(ex, ErrorCodes::UnknownError);
×
138
    }
×
139
    // FIXME: Handle more exception types.
140
    catch (...) {
101✔
141
        m_err->error = RLM_ERR_UNKNOWN;
×
142
        m_message_buf = "Unknown error";
×
143
        m_err->message = m_message_buf.c_str();
×
144
    }
×
145
}
101✔
146

147
bool ErrorStorage::has_error() const noexcept
148
{
4✔
149
    return static_cast<bool>(m_err);
4✔
150
}
4✔
151

152
bool ErrorStorage::get_as_realm_error_t(realm_error_t* out) const noexcept
153
{
125✔
154
    if (!m_err) {
125✔
155
        return false;
31✔
156
    }
31✔
157

158
    if (out) {
94✔
159
        *out = *m_err;
94✔
160
    }
94✔
161
    return true;
94✔
162
}
125✔
163

164
bool ErrorStorage::clear() noexcept
165
{
99✔
166
    auto ret = static_cast<bool>(m_err);
99✔
167
    m_err.reset();
99✔
168
    return ret;
99✔
169
}
99✔
170

171
void ErrorStorage::set_user_code_error(void* user_code_error)
172
{
3✔
173
    m_user_code_error = user_code_error;
3✔
174
}
3✔
175

176
void* ErrorStorage::get_and_clear_user_code_error()
177
{
11✔
178
    auto ret = m_user_code_error;
11✔
179
    m_user_code_error = nullptr;
11✔
180
    return ret;
11✔
181
}
11✔
182

183
ErrorStorage* ErrorStorage::get_thread_local()
184
{
340✔
185
#if !defined(RLM_NO_THREAD_LOCAL)
340✔
186
    static thread_local ErrorStorage g_error_storage;
340✔
187
    return &g_error_storage;
340✔
188
#else
189
    static pthread_key_t g_last_exception_key;
190
    static pthread_once_t g_last_exception_key_init_once = PTHREAD_ONCE_INIT;
191

192
    pthread_once(&g_last_exception_key_init_once, [] {
193
        pthread_key_create(&g_last_exception_key, [](void* ptr) {
194
            delete reinterpret_cast<ErrorStorage*>(ptr);
195
        });
196
    });
197

198
    if (auto ptr = reinterpret_cast<ErrorStorage*>(pthread_getspecific(g_last_exception_key)); ptr != nullptr) {
199
        return ptr;
200
    }
201

202
    auto ptr = new ErrorStorage{};
203
    pthread_setspecific(g_last_exception_key, ptr);
204
    return ptr;
205
#endif
206
}
340✔
207

208
void set_last_exception(std::exception_ptr eptr)
209
{
100✔
210
    ErrorStorage::get_thread_local()->assign(std::move(eptr));
100✔
211
}
100✔
212

213
RLM_API bool realm_get_last_error(realm_error_t* err)
214
{
121✔
215
    return ErrorStorage::get_thread_local()->get_as_realm_error_t(err);
121✔
216
}
121✔
217

218
RLM_API bool realm_clear_last_error()
219
{
99✔
220
    return ErrorStorage::get_thread_local()->clear();
99✔
221
}
99✔
222

223
RLM_API realm_async_error_t* realm_get_last_error_as_async_error(void)
224
{
4✔
225
    if (!ErrorStorage::get_thread_local()->has_error()) {
4✔
226
        return nullptr;
2✔
227
    }
2✔
228

229
    return new realm_async_error_t{*ErrorStorage::get_thread_local()};
2✔
230
}
4✔
231

232
RLM_API bool realm_get_async_error(const realm_async_error_t* async_err, realm_error_t* out_err)
233
{
7✔
234
    if (!async_err)
7✔
235
        return false;
3✔
236

237
    return async_err->error_storage.get_as_realm_error_t(out_err);
4✔
238
}
7✔
239

240
} // namespace realm::c_api
241

242
RLM_EXPORT bool realm_wrap_exceptions(void (*func)()) noexcept
243
{
4✔
244
    return realm::c_api::wrap_err([=]() {
4✔
245
        (func)();
4✔
246
        return true;
4✔
247
    });
4✔
248
}
4✔
249

250
RLM_API void realm_register_user_code_callback_error(void* user_code_error) noexcept
251
{
3✔
252
    realm::c_api::ErrorStorage::get_thread_local()->set_user_code_error(user_code_error);
3✔
253
}
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc