Skip to content

Commit

Permalink
Merge pull request #849 from PowerGridModel/feature/error-message-fix
Browse files Browse the repository at this point in the history
MessagePack deserialization: improve error messages
  • Loading branch information
TonyXiang8787 authored Dec 4, 2024
2 parents 4954709 + 964abd2 commit 0139a97
Showing 1 changed file with 6 additions and 6 deletions.
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 ? "Map or an array expected." : "Map expected.") : "Array expected.";

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 = "String expected.";

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 = "Boolean expected.";

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 = "Integer expected.";

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 = "Number expected.";

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 = "Array of 3 numbers expected.";

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

0 comments on commit 0139a97

Please sign in to comment.