Skip to content

Commit

Permalink
Merge pull request #523 from vizzuhq/add_df_exceptions
Browse files Browse the repository at this point in the history
Add dataframe exceptions
  • Loading branch information
schaumb authored May 16, 2024
2 parents 573e50b + ad98890 commit c16c294
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 63 deletions.
26 changes: 23 additions & 3 deletions src/dataframe/impl/data_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ cell_value data_source::get_data(std::size_t record_id,
return meas.values[record_id];
}
case unknown:
default: error();
default: error(error_type::series_not_found, column);
}
}

Expand Down Expand Up @@ -293,7 +293,7 @@ void data_source::finalize()
for (std::size_t r{}; r < records; ++r)
if (!finalized.try_emplace(get_id(r, dimension_names), r)
.second)
error();
error(error_type::record, "dup");
}
}
data_source::dimension_t &data_source::add_new_dimension(
Expand Down Expand Up @@ -561,7 +561,27 @@ void data_source::dimension_t::add_element(
if (values.emplace_back(get_or_set_cat(cat)) == nav)
contains_nav = true;
}
void error() { throw std::runtime_error("dataframe"); }

constexpr std::string_view unique_enum_names(error_type)
{
return "series not found,duplicated series,wrong type,"
"aggregator,sort,nan,record,unimplemented,internal error";
}

void error(error_type err_t, std::string_view arg)
{
auto &&[data, size] =
Refl::enum_name<std::pair<const char *, int>>(err_t);
std::array<char, 64> arr{};
[[maybe_unused]] auto &&_ = std::snprintf(arr.data(),
arr.size(),
"dataframe error: %.*s: %.*s",
size,
data,
static_cast<int>(arg.size()),
arg.data());
throw std::runtime_error(arr.data());
}

void data_source::dimension_t::add_more_data(
std::span<const char *const> new_categories,
Expand Down
15 changes: 14 additions & 1 deletion src/dataframe/impl/data_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@ namespace Vizzu::dataframe

enum class series_type { unknown, dimension, measure };

[[maybe_unused]] [[noreturn]] void error();
enum class error_type {
series_not_found,
duplicated_series,
wrong_type,
aggregator,
sort,
nan,
record,
unimplemented,
internal_error
};

[[maybe_unused]] [[noreturn]] void error(error_type err,
std::string_view arg = {});

class data_source : public std::enable_shared_from_this<data_source>
{
Expand Down
Loading

0 comments on commit c16c294

Please sign in to comment.