Skip to content

Conversation

@k-wasniowski
Copy link

No description provided.

Comment on lines +46 to +51
SFrameError(const SFrameError& other)
: type_(SFrameErrorType::none)
, message_(other.message_)
{
type_ = other.type_;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need to be non-default? Similar question with several of the methods below.


private:
SFrameErrorType type_ = SFrameErrorType::none;
std::string message_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love having STL containers here. Since we have a fixed list of messages, let's just define const char* constants for them and refer to them. Especially since that's how we're exposing them anyway!

// Error types to replace exceptions
enum class SFrameErrorType
{
none = 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this option (but still start numbering at 1) and the SFrameError::ok() method.

}

// Copy assignment
SFrameError& operator=(const SFrameError& other)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not clear that this type needs to be assignable. If it causes conflict with the const char* note below, I would drop the operator=.

Comment on lines +92 to +93
void
throw_on_error(const SFrameError& error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing this, I would have a method Result::unwrap that throws on error. This also works well with eliminating SFrameErrorType::none. And it will save you having to write branches on is_ok().

Comment on lines +133 to +142
Result(Result&& other) noexcept
: data_(std::move(other.data_))
{
}

Result& operator=(Result&& other) noexcept
{
data_ = std::move(other.data_);
return *this;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these not the same as the default?

Comment on lines +172 to +173
private:
std::variant<T, SFrameError> data_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor note: If T = SFrameError, I think this class will fail to compile and/or produce weird results (e.g., from is_ok / is_err). I don't think this is a case we need to accommodate, though.

return *this;
}

T value() { return std::move(std::get<T>(data_)); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would follow Rust here and call this unwrap. Note that it has "throw if error" semantics anyway, because if it contains an error, std::get will throw bad_variant_access if is_err.

Comment on lines +233 to +234
bool is_ok_;
SFrameError error_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would replace these with std::optional<SFrameError>. Even less need for SFrameError::none.

Comment on lines +40 to +42
auto decode_result = Header::parse(tc.encoding);
REQUIRE(decode_result.is_ok());
const auto decoded = decode_result.value();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you have unwrap(), these three lines will compress back to:

const auto decoded = Header::parse(tc.encoding).unwrap();

... since unwrap will throw and fail the test if is_err.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants