Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RCORE-2005: Include nested path in 'OutOfBounds' error message #7489

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Enhancements
* <New feature description> (PR [#????](https://github.com/realm/realm-core/pull/????))
* None.
* Nested path included in 'OutOfBoundsø error message ([#7438](https://github.com/realm/realm-core/issues/7438))

### Fixed
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
Expand Down
9 changes: 9 additions & 0 deletions src/realm/collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,13 @@ UpdateStatus CollectionBase::do_init_from_parent(BPlusTreeBase* tree, ref_type r
return UpdateStatus::Updated;
}

void CollectionBase::out_of_bounds(const char* msg, size_t index, size_t size) const
{
auto path = get_short_path();
path.erase(path.begin());
throw OutOfBounds(util::format("%1 on %2 '%3.%4%5'", msg, collection_type_name(get_collection_type()),
get_table()->get_class_name(), get_property_name(), path),
index, size);
}

} // namespace realm
18 changes: 7 additions & 11 deletions src/realm/collection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,13 @@ class CollectionBase : public Collection {
CollectionBase& operator=(const CollectionBase&) noexcept = default;
CollectionBase& operator=(CollectionBase&&) noexcept = default;

void validate_index(const char* msg, size_t index, size_t size) const;
void validate_index(const char* msg, size_t index, size_t size) const
{
if (index >= size) {
out_of_bounds(msg, index, size);
}
}
void out_of_bounds(const char* msg, size_t index, size_t size) const;
static UpdateStatus do_init_from_parent(BPlusTreeBase* tree, ref_type ref, bool allow_create);
};

Expand All @@ -277,16 +283,6 @@ inline std::string_view collection_type_name(CollectionType col_type, bool upper
return "";
}

inline void CollectionBase::validate_index(const char* msg, size_t index, size_t size) const
{
if (index >= size) {
throw OutOfBounds(util::format("%1 on %2 '%3.%4'", msg, collection_type_name(get_collection_type()),
get_table()->get_class_name(), get_property_name()),
index, size);
}
}


template <class T>
inline void check_column_type(ColKey col)
{
Expand Down
3 changes: 3 additions & 0 deletions test/test_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,9 @@ TEST(List_NestedList_Path)
CHECK_EQUAL(path.path_from_top[0], col_child);
CHECK_EQUAL(path.path_from_top[1], "Any");
CHECK_EQUAL(path.path_from_top[2], "Foo");
std::string message;
CHECK_THROW_ANY_GET_MESSAGE(list_int->set(7, 0), message);
CHECK(message.find("Any['Foo']") != std::string::npos);
}

// Collections contained in Mixed
Expand Down
Loading