diff --git a/src/main.cpp b/src/main.cpp index 8d4f8be..bc94a59 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,17 +23,18 @@ #include #pragma GCC diagnostic pop -#include #include #include #include +#include #include -#include #include #include -#include +#include #include #include +#include +#include #include #include "irods/private/re/python.hpp" @@ -118,44 +119,41 @@ namespace // Reference counter for nested python operations static thread_local uint64_t ts_thread_refct = 0; } //namespace python_state -} -void register_regexes_from_array(const nlohmann::json& _array, const std::string& _instance_name) -{ - try { - for (const auto& elem : _array) { - try { - const auto& tmp = elem.get_ref(); - RuleExistsHelper::Instance()->registerRuleRegex(tmp); - // clang-format off - log_re::debug({ - {"rule_engine_plugin", rule_engine_name}, - {"instance_name", _instance_name}, - {"regex", tmp}, - }); - // clang-format on - } - catch (const boost::bad_any_cast&) { - // clang-format off - log_re::error({ - {"rule_engine_plugin", rule_engine_name}, - {"instance_name", _instance_name}, - {"log_message", "failed to cast pep_regex_to_match to string"}, - }); - // clang-format on - continue; + void register_regexes_from_array(const nlohmann::json& _array, const std::string& _instance_name) + { + try { + for (const auto& elem : _array) { + try { + const auto& tmp = elem.get_ref(); + RuleExistsHelper::Instance()->registerRuleRegex(tmp); + // clang-format off + log_re::debug({ + {"rule_engine_plugin", rule_engine_name}, + {"instance_name", _instance_name}, + {"regex", tmp}, + }); + // clang-format on + } + catch (const boost::bad_any_cast&) { + // clang-format off + log_re::error({ + {"rule_engine_plugin", rule_engine_name}, + {"instance_name", _instance_name}, + {"log_message", "failed to cast pep_regex_to_match to string"}, + }); + // clang-format on + continue; + } } } + catch (const boost::bad_any_cast&) { + std::stringstream msg; + msg << "[" << _instance_name << "] failed to any_cast a std::vector&"; + THROW(INVALID_ANY_CAST, msg.str()); + } } - catch (const boost::bad_any_cast&) { - std::stringstream msg; - msg << "[" << _instance_name << "] failed to any_cast a std::vector&"; - THROW(INVALID_ANY_CAST, msg.str()); - } -} -namespace -{ irods::error to_irods_error_object(const bp::object& object) { if (bp::extract result{object}; result.check()) { @@ -610,6 +608,17 @@ static irods::error exec_rule(const irods::default_re_ctx&, std::list& rule_arguments_cpp, irods::callback effect_handler) { + // Clear client-side errors for dynamic PEPs as we expect failures from the pre-PEPs to control + // access to operations. This comment and behavior come directly from the NREP. + irods::at_scope_exit clear_rerror_stack_for_dynamic_peps{[&rule_name, &effect_handler] { + if (rule_name.starts_with("pep_")) { + auto* rei = get_rei_from_effect_handler(effect_handler); + if (rei && rei->rsComm) { + freeRErrorContent(&rei->rsComm->rError); + } + } + }}; + try { std::lock_guard lock{python_mutex}; python_thread_state_scope tstate;