Skip to content

Commit

Permalink
Merge pull request #260 from chaoticgd/result_messages
Browse files Browse the repository at this point in the history
Improve assertion error messages for the Result type
  • Loading branch information
chaoticgd authored Oct 23, 2024
2 parents d199184 + 1226d5a commit 6989df0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/ccc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class [[nodiscard]] Result {
template <typename OtherValue>
Result(Result<OtherValue>&& rhs)
{
CCC_ASSERT(rhs.m_error != nullptr);
CCC_ABORT_IF_FALSE(rhs.m_error != nullptr, "Tried to convert a Result object containing a value to another type.");
m_error = std::move(rhs.m_error);
}

Expand All @@ -119,31 +119,31 @@ class [[nodiscard]] Result {

const Error& error() const
{
CCC_ASSERT(m_error != nullptr);
CCC_ABORT_IF_FALSE(m_error != nullptr, "Called error() on a Result object that doesn't contain an error.");
return *m_error;
}

Value& operator*()
{
CCC_ASSERT(m_error == nullptr);
CCC_ABORT_IF_FALSE(m_error == nullptr, "Dereferenced Result object that does not contain a value.");
return m_value;
}

const Value& operator*() const
{
CCC_ASSERT(m_error == nullptr);
CCC_ABORT_IF_FALSE(m_error == nullptr, "Dereferenced Result object that does not contain a value.");
return m_value;
}

Value* operator->()
{
CCC_ASSERT(m_error == nullptr);
CCC_ABORT_IF_FALSE(m_error == nullptr, "Used arrow operator on Result object that does not contain a value.");
return &m_value;
}

const Value* operator->() const
{
CCC_ASSERT(m_error == nullptr);
CCC_ABORT_IF_FALSE(m_error == nullptr, "Used arrow operator on Result object that does not contain a value.");
return &m_value;
}
};
Expand Down

0 comments on commit 6989df0

Please sign in to comment.