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

realm / realm-core / 2593

30 Aug 2024 07:57AM UTC coverage: 91.109% (+0.002%) from 91.107%
2593

push

Evergreen

web-flow
New changelog section to prepare for vNext (#8014)

Co-authored-by: jedelbo <572755+jedelbo@users.noreply.github.com>

102812 of 181608 branches covered (56.61%)

217367 of 238580 relevant lines covered (91.11%)

5740894.1 hits per line

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

91.59
/src/realm/exceptions.cpp
1
/*************************************************************************
2
 *
3
 * Copyright 2016 Realm Inc.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 **************************************************************************/
18

19
#include <realm/exceptions.hpp>
20

21
#include <realm/version.hpp>
22
#include <realm/util/to_string.hpp>
23
#include <realm/util/demangle.hpp>
24

25
namespace realm {
26

27
const char* Exception::what() const noexcept
28
{
12,192✔
29
    return reason().data();
12,192✔
30
}
12,192✔
31

32
const Status& Exception::to_status() const
33
{
1,383✔
34
    return m_status;
1,383✔
35
}
1,383✔
36

37
std::string_view Exception::reason() const noexcept
38
{
15,054✔
39
    return m_status.reason();
15,054✔
40
}
15,054✔
41

42
ErrorCodes::Error Exception::code() const noexcept
43
{
13,569✔
44
    return m_status.code();
13,569✔
45
}
13,569✔
46

47
ErrorCategory Exception::category() const noexcept
48
{
×
49
    return ErrorCodes::error_categories(code());
×
50
}
×
51

52
std::string_view Exception::code_string() const noexcept
53
{
1,134✔
54
    return m_status.code_string();
1,134✔
55
}
1,134✔
56

57
Exception::Exception(ErrorCodes::Error err, std::string_view str)
58
    : m_status(err, str)
9,855✔
59
{
19,776✔
60
}
19,776✔
61

62
Exception::Exception(Status status)
63
    : m_status(std::move(status))
576✔
64
{
1,152✔
65
}
1,152✔
66

67
// Apple implementation in exceptions.mm
68
#if !REALM_PLATFORM_APPLE
69
Status exception_to_status() noexcept
70
{
426✔
71
    try {
426✔
72
        throw;
426✔
73
    }
426✔
74
    catch (const Exception& e) {
426✔
75
        return e.to_status();
420✔
76
    }
420✔
77
    catch (const std::exception& e) {
426✔
78
        return Status(ErrorCodes::UnknownError,
6✔
79
                      util::format("Caught std::exception of type %1: %2", util::get_type_name(e), e.what()));
6✔
80
    }
6✔
81
    catch (...) {
426✔
82
        REALM_UNREACHABLE();
83
    }
84
}
426✔
85
#endif // !REALM_PLATFORM_APPLE
86

87
UnsupportedFileFormatVersion::UnsupportedFileFormatVersion(int version)
88
    : Exception(ErrorCodes::UnsupportedFileFormatVersion,
6✔
89
                util::format("Database has an unsupported version (%1) and cannot be upgraded", version))
6✔
90
    , source_version(version)
6✔
91
{
12✔
92
}
12✔
93
UnsupportedFileFormatVersion::~UnsupportedFileFormatVersion() noexcept = default;
12✔
94

95

96
LogicError::LogicError(ErrorCodes::Error code, std::string_view msg)
97
    : Exception(code, msg)
8,022✔
98
{
16,071✔
99
    REALM_ASSERT(ErrorCodes::error_categories(code).test(ErrorCategory::logic_error));
16,071✔
100
}
16,071✔
101
LogicError::~LogicError() noexcept = default;
16,065✔
102

103

104
RuntimeError::RuntimeError(ErrorCodes::Error code, std::string_view msg)
105
    : Exception(code, msg)
579✔
106
{
1,188✔
107
    REALM_ASSERT(ErrorCodes::error_categories(code).test(ErrorCategory::runtime_error));
1,188✔
108
}
1,188✔
109
RuntimeError::RuntimeError(Status&& status)
110
    : Exception(std::move(status))
30✔
111
{
60✔
112
    REALM_ASSERT(ErrorCodes::error_categories(to_status().code()).test(ErrorCategory::runtime_error));
60✔
113
}
60✔
114
RuntimeError::~RuntimeError() noexcept = default;
1,248✔
115

116
InvalidArgument::InvalidArgument(std::string_view msg)
117
    : InvalidArgument(ErrorCodes::InvalidArgument, msg)
366✔
118
{
732✔
119
}
732✔
120

121
InvalidArgument::InvalidArgument(ErrorCodes::Error code, std::string_view msg)
122
    : LogicError(code, msg)
3,432✔
123
{
6,864✔
124
    REALM_ASSERT(ErrorCodes::error_categories(code).test(ErrorCategory::invalid_argument));
6,864✔
125
}
6,864✔
126
InvalidArgument::~InvalidArgument() noexcept = default;
6,864✔
127

128

129
OutOfBounds::OutOfBounds(std::string_view msg, size_t idx, size_t sz)
130
    : InvalidArgument(ErrorCodes::OutOfBounds,
417✔
131
                      sz == 0 ? util::format("Requested index %1 calling %2 when empty", idx, msg)
417✔
132
                              : util::format("Requested index %1 calling %2 when max is %3", idx, msg, sz - 1))
417✔
133
    , index(idx)
417✔
134
    , size(sz)
417✔
135
{
834✔
136
}
834✔
137
OutOfBounds::~OutOfBounds() noexcept = default;
834✔
138

139

140
FileAccessError::FileAccessError(ErrorCodes::Error code, std::string_view msg, std::string_view path, int err)
141
    : RuntimeError(code, msg)
507✔
142
    , m_path(path)
507✔
143
    , m_errno(err)
507✔
144
{
1,044✔
145
    REALM_ASSERT(ErrorCodes::error_categories(code).test(ErrorCategory::file_access));
1,044✔
146
}
1,044✔
147
FileAccessError::~FileAccessError() noexcept = default;
1,044✔
148

149
// Out-of-line virtual destructors for each of the exception types "anchors"
150
// the vtable and makes it so that it doesn't have to be emitted into each TU
151
// which uses the exception type
152
KeyAlreadyUsed::~KeyAlreadyUsed() noexcept = default;
15✔
153
MaximumFileSizeExceeded::~MaximumFileSizeExceeded() noexcept = default;
×
154
OutOfDiskSpace::~OutOfDiskSpace() noexcept = default;
×
155
MultipleSyncAgents::~MultipleSyncAgents() noexcept = default;
18✔
156
AddressSpaceExhausted::~AddressSpaceExhausted() noexcept = default;
×
157
InvalidColumnKey::~InvalidColumnKey() noexcept = default;
348✔
158
NoSuchTable::~NoSuchTable() noexcept = default;
54✔
159
TableNameInUse::~TableNameInUse() noexcept = default;
12✔
160
KeyNotFound::~KeyNotFound() noexcept = default;
864✔
161
NotNullable::~NotNullable() noexcept = default;
78✔
162
PropertyTypeMismatch::~PropertyTypeMismatch() noexcept = default;
60✔
163
InvalidEncryptionKey::~InvalidEncryptionKey() noexcept = default;
12✔
164
StaleAccessor::~StaleAccessor() noexcept = default;
198✔
165
IllegalOperation::~IllegalOperation() noexcept = default;
4,452✔
166
NoSubscriptionForWrite::~NoSubscriptionForWrite() noexcept = default;
6✔
167
WrongTransactionState::~WrongTransactionState() noexcept = default;
1,032✔
168
InvalidTableRef::~InvalidTableRef() noexcept = default;
42✔
169
SerializationError::~SerializationError() noexcept = default;
×
170
NotImplemented::~NotImplemented() noexcept = default;
×
171
MigrationFailed::~MigrationFailed() noexcept = default;
30✔
172
SyncSchemaMigrationFailed::~SyncSchemaMigrationFailed() noexcept = default;
×
173
ObjectAlreadyExists::~ObjectAlreadyExists() noexcept = default;
24✔
174
CrossTableLinkTarget::~CrossTableLinkTarget() noexcept = default;
18✔
175
SystemError::~SystemError() noexcept = default;
36✔
176
query_parser::SyntaxError::~SyntaxError() noexcept = default;
1,116✔
177
query_parser::InvalidQueryError::~InvalidQueryError() noexcept = default;
1,812✔
178
query_parser::InvalidQueryArgError::~InvalidQueryArgError() noexcept = default;
426✔
179

180
} // namespace realm
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