Skip to content

Commit

Permalink
Rename EverestCmdError to CmdError
Browse files Browse the repository at this point in the history
Handle cmd timeout with new cmd error mechanism

Add HandlerException and CmdTimeout exceptions that modules can specifically handle

Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
  • Loading branch information
hikinggrass committed Dec 12, 2024
1 parent 7908c53 commit cfd461d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
12 changes: 11 additions & 1 deletion include/framework/everest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,21 @@ struct CmdResult {
std::optional<ErrorMessage> error;
};

class EverestCmdError : public Everest::EverestBaseRuntimeError {
class CmdError : public Everest::EverestBaseRuntimeError {
public:
using EverestBaseRuntimeError::EverestBaseRuntimeError;
};

class HandlerException : public CmdError {
public:
using CmdError::CmdError;
};

class CmdTimeout : public CmdError {
public:
using CmdError::CmdError;
};

namespace error {
struct ErrorDatabaseMap;
struct ErrorManagerImpl;
Expand Down
31 changes: 20 additions & 11 deletions lib/everest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,16 +420,18 @@ json Everest::call_cmd(const Requirement& req, const std::string& cmd_name, json
return;
}

EVLOG_verbose << fmt::format(
"Incoming res {} for {}->{}()", data_id,
this->config.printable_identifier(connection["module_id"], connection["implementation_id"]), cmd_name);

if (data.contains("error")) {
EVLOG_error << fmt::format(
"Received error {} for {}->{}()", data.at("error"),
this->config.printable_identifier(connection["module_id"], connection["implementation_id"]), cmd_name);
"{}:{} during command call: {}->{}()", data.at("error").at("type"), data.at("error").at("msg"),
this->config.printable_identifier(connection.at("module_id"), connection.at("implementation_id")),
cmd_name);
res_promise.set_value(CmdResult{std::nullopt, data.at("error")});
} else {
EVLOG_verbose << fmt::format(
"Incoming res {} for {}->{}()", data_id,
this->config.printable_identifier(connection.at("module_id"), connection.at("implementation_id")),
cmd_name);

res_promise.set_value(CmdResult{std::move(data["retval"]), std::nullopt});
}
};
Expand Down Expand Up @@ -458,9 +460,11 @@ json Everest::call_cmd(const Requirement& req, const std::string& cmd_name, json

CmdResult result;
if (res_future_status == std::future_status::timeout) {
EVLOG_AND_THROW(EverestTimeoutError(fmt::format(
"Timeout while waiting for result of {}->{}()",
this->config.printable_identifier(connection["module_id"], connection["implementation_id"]), cmd_name)));
result.error = ErrorMessage{
ErrorType::Timeout,
fmt::format("Timeout while waiting for result of {}->{}()",
this->config.printable_identifier(connection["module_id"], connection["implementation_id"]),
cmd_name)};
}
if (res_future_status == std::future_status::ready) {
result = res_future.get();
Expand All @@ -469,9 +473,14 @@ json Everest::call_cmd(const Requirement& req, const std::string& cmd_name, json

if (result.error.has_value()) {
auto& error = result.error.value();
throw EverestCmdError(fmt::format("{}: {}", conversions::error_type_to_string(error.type), error.msg));
if (error.type == ErrorType::HandlerException) {
throw HandlerException(fmt::format("{}", error.msg));
} else if (error.type == ErrorType::Timeout) {
throw CmdTimeout(fmt::format("{}", error.msg));
}
throw CmdError(fmt::format("{}: {}", conversions::error_type_to_string(error.type), error.msg));
} else if (not result.result.has_value()) {
throw EverestCmdError("Command did not return result");
throw CmdError("Command did not return result");
} else {
return result.result.value();
}
Expand Down

0 comments on commit cfd461d

Please sign in to comment.