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

MessagePack deserialization: improve error messages #849

Merged
merged 5 commits into from
Dec 4, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ struct MapArrayVisitor : DefaultErrorVisitor<MapArrayVisitor<map_array>> {
static constexpr bool enable_array =
std::same_as<map_array, visit_array_t> || std::same_as<map_array, visit_map_array_t>;
static constexpr std::string_view static_err_msg =
enable_map ? (enable_array ? "Expect a map or array." : "Expect a map.") : "Expect an array.";
enable_map ? (enable_array ? "Expected a map or array." : "Expected a map.") : "Expected an array.";
mgovers marked this conversation as resolved.
Show resolved Hide resolved

Idx size{};
bool is_map{};
Expand Down Expand Up @@ -226,7 +226,7 @@ struct MapArrayVisitor : DefaultErrorVisitor<MapArrayVisitor<map_array>> {
};

struct StringVisitor : DefaultErrorVisitor<StringVisitor> {
static constexpr std::string_view static_err_msg = "Expect a string.";
static constexpr std::string_view static_err_msg = "Expected a string.";

std::string_view str{};
bool visit_str(const char* v, uint32_t size) {
Expand All @@ -236,7 +236,7 @@ struct StringVisitor : DefaultErrorVisitor<StringVisitor> {
};

struct BoolVisitor : DefaultErrorVisitor<BoolVisitor> {
static constexpr std::string_view static_err_msg = "Expect a boolean.";
static constexpr std::string_view static_err_msg = "Expected a boolean.";

bool value{};
bool visit_boolean(bool v) {
Expand All @@ -248,7 +248,7 @@ struct BoolVisitor : DefaultErrorVisitor<BoolVisitor> {
template <class T> struct ValueVisitor;

template <std::integral T> struct ValueVisitor<T> : DefaultErrorVisitor<ValueVisitor<T>> {
static constexpr std::string_view static_err_msg = "Expect an interger.";
static constexpr std::string_view static_err_msg = "Expected an integer.";
mgovers marked this conversation as resolved.
Show resolved Hide resolved

T& value; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)

Expand All @@ -270,7 +270,7 @@ template <std::integral T> struct ValueVisitor<T> : DefaultErrorVisitor<ValueVis
};

template <> struct ValueVisitor<double> : DefaultErrorVisitor<ValueVisitor<double>> {
static constexpr std::string_view static_err_msg = "Expect a number.";
static constexpr std::string_view static_err_msg = "Expected a number.";

double& value; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)

Expand All @@ -294,7 +294,7 @@ template <> struct ValueVisitor<double> : DefaultErrorVisitor<ValueVisitor<doubl
};

template <> struct ValueVisitor<RealValue<asymmetric_t>> : DefaultErrorVisitor<ValueVisitor<RealValue<asymmetric_t>>> {
static constexpr std::string_view static_err_msg = "Expect an array of 3 numbers.";
static constexpr std::string_view static_err_msg = "Expected an array of 3 numbers.";

RealValue<asymmetric_t>& value; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
Idx idx{};
Expand Down
Loading