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

realm / realm-core / github_pull_request_281750

30 Oct 2023 03:37PM UTC coverage: 90.528% (-1.0%) from 91.571%
github_pull_request_281750

Pull #6073

Evergreen

jedelbo
Log free space and history sizes when opening file
Pull Request #6073: Merge next-major

95488 of 175952 branches covered (0.0%)

8973 of 12277 new or added lines in 149 files covered. (73.09%)

622 existing lines in 51 files now uncovered.

233503 of 257934 relevant lines covered (90.53%)

6533720.56 hits per line

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

87.78
/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
{
11,934✔
29
    return reason().data();
11,934✔
30
}
11,934✔
31

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

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

42
ErrorCodes::Error Exception::code() const noexcept
43
{
12,975✔
44
    return m_status.code();
12,975✔
45
}
12,975✔
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,026✔
54
    return m_status.code_string();
1,026✔
55
}
1,026✔
56

57
Exception::Exception(ErrorCodes::Error err, std::string_view str)
58
    : m_status(err, str)
59
{
18,834✔
60
}
18,834✔
61

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

67
Status exception_to_status() noexcept
68
{
708✔
69
    try {
708✔
70
        throw;
708✔
71
    }
708✔
72
    catch (const Exception& e) {
702✔
73
        return e.to_status();
702✔
74
    }
702✔
75
    catch (const std::exception& e) {
6✔
76
        return Status(ErrorCodes::UnknownError,
6✔
77
                      util::format("Caught std::exception of type %1: %2", util::get_type_name(e), e.what()));
6✔
78
    }
6✔
79
    catch (...) {
×
80
        REALM_UNREACHABLE();
×
81
    }
×
82
}
708✔
83

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

92

93
LogicError::LogicError(ErrorCodes::Error code, std::string_view msg)
94
    : Exception(code, msg)
95
{
15,930✔
96
    REALM_ASSERT(ErrorCodes::error_categories(code).test(ErrorCategory::logic_error));
15,930✔
97
}
15,930✔
98
LogicError::~LogicError() noexcept = default;
15,936✔
99

100

101
RuntimeError::RuntimeError(ErrorCodes::Error code, std::string_view msg)
102
    : Exception(code, msg)
103
{
708✔
104
    REALM_ASSERT(ErrorCodes::error_categories(code).test(ErrorCategory::runtime_error));
708✔
105
}
708✔
106
RuntimeError::RuntimeError(Status&& status)
107
    : Exception(std::move(status))
108
{
60✔
109
    REALM_ASSERT(ErrorCodes::error_categories(to_status().code()).test(ErrorCategory::runtime_error));
60✔
110
}
60✔
111
RuntimeError::~RuntimeError() noexcept = default;
864✔
112

113
InvalidArgument::InvalidArgument(std::string_view msg)
114
    : InvalidArgument(ErrorCodes::InvalidArgument, msg)
115
{
708✔
116
}
708✔
117

118
InvalidArgument::InvalidArgument(ErrorCodes::Error code, std::string_view msg)
119
    : LogicError(code, msg)
120
{
6,768✔
121
    REALM_ASSERT(ErrorCodes::error_categories(code).test(ErrorCategory::invalid_argument));
6,768✔
122
}
6,768✔
123
InvalidArgument::~InvalidArgument() noexcept = default;
6,768✔
124

125

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

136

137
FileAccessError::FileAccessError(ErrorCodes::Error code, std::string_view msg, std::string_view path, int err)
138
    : RuntimeError(code, msg)
139
    , m_path(path)
140
    , m_errno(err)
141
{
552✔
142
    REALM_ASSERT(ErrorCodes::error_categories(code).test(ErrorCategory::file_access));
552✔
143
}
552✔
144
FileAccessError::~FileAccessError() noexcept = default;
552✔
145

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

176
} // 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