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

pandaproxy: Invert error_code dependencies #4722

Merged
merged 5 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions src/v/pandaproxy/error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const reply_error_category reply_error_category{};
std::error_condition make_error_condition(std::error_code ec) {
using rec = reply_error_code;
using kec = kafka::error_code;
using pec = pandaproxy::parse::error_code;

if (ec.category() == make_error_code(kec::none).category()) {
switch (static_cast<kec>(ec.value())) {
Expand Down Expand Up @@ -190,6 +191,17 @@ std::error_condition make_error_condition(std::error_code ec) {
return rec::kafka_authentication_error;
}
return {}; // keep gcc happy
} else if (ec.category() == make_error_code(pec::empty_param).category()) {
switch (static_cast<pec>(ec.value())) {
case pec::empty_param:
Copy link
Member

Choose a reason for hiding this comment

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

nit: [[fallthrough]];

Copy link
Member Author

Choose a reason for hiding this comment

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

I tend to do that only for cases where there is a statement. I don't think the compiler will warn unless there is a statement, anyhow.

Copy link
Member

Choose a reason for hiding this comment

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

hmm, i thought clang-tidy warned in this case, but indeed im not see it.

case pec::invalid_param:
return rec::kafka_bad_request;
case pec::not_acceptable:
return rec::not_acceptable;
case pec::unsupported_media_type:
return rec::unsupported_media_type;
}
return {};
}
return ec.default_error_condition();
}
Expand Down
16 changes: 0 additions & 16 deletions src/v/pandaproxy/parsing/error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

#include "error.h"

#include "pandaproxy/error.h"

namespace pandaproxy::parse {

namespace {
Expand All @@ -32,20 +30,6 @@ struct error_category final : std::error_category {
}
return "(unrecognized error)";
}

std::error_condition
default_error_condition(int ec) const noexcept override {
switch (static_cast<error_code>(ec)) {
case error_code::empty_param:
case error_code::invalid_param:
return reply_error_code::kafka_bad_request;
case error_code::not_acceptable:
return reply_error_code::not_acceptable;
case error_code::unsupported_media_type:
return reply_error_code::unsupported_media_type;
}
return {};
}
};

const error_category ppp_error_category{};
Expand Down
10 changes: 5 additions & 5 deletions src/v/pandaproxy/parsing/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@
namespace pandaproxy::parse {

struct exception_base : std::exception {
explicit exception_base(std::error_condition err)
explicit exception_base(std::error_code err)
: std::exception{}
, error{err}
, msg{err.message()} {}
exception_base(std::error_condition err, std::string_view msg)
exception_base(std::error_code err, std::string_view msg)
: std::exception{}
, error{err}
, msg{msg} {}
const char* what() const noexcept final { return msg.c_str(); }
std::error_condition error;
std::error_code error;
std::string msg;
};

class error final : public exception_base {
public:
explicit error(error_code ec)
: exception_base(make_error_code(ec).default_error_condition()) {}
: exception_base(ec) {}
error(error_code ec, std::string_view msg)
: exception_base(make_error_code(ec).default_error_condition(), msg) {}
: exception_base(ec, msg) {}
};

} // namespace pandaproxy::parse